package com.hp.bon.sgw.wh.channel;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.ws.rs.Path;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.simpleframework.http.ContentType;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerProcessor;
import org.simpleframework.http.core.ContainerSelector;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.asiainfo.webservice.QueryNetInvoiceResponseItemExt;
import com.asiainfo.webservice.impl.BillingBossServiceImplServiceSoapBindingStub;
import com.google.gson.Gson;
import com.hp.bon.sgw.Constants;
import com.hp.bon.sgw.Constants.MessageType;
import com.hp.bon.sgw.Constants.NodeStatus;
import com.hp.bon.sgw.bean.AuthResult;
import com.hp.bon.sgw.bean.CongestionBean;
import com.hp.bon.sgw.bean.SysParamBean;
import com.hp.bon.sgw.bean.XmlMessage;
import com.hp.bon.sgw.core.BuzProcessorManager;
import com.hp.bon.sgw.core.CallParam;
import com.hp.bon.sgw.core.channel.IChannel;
import com.hp.bon.sgw.core.channel.handler.BaseWSCallHandler;
import com.hp.bon.sgw.domain.MessageDetail;
import com.hp.bon.sgw.domain.Node;
import com.hp.bon.sgw.domain.SGWChannel;
import com.hp.bon.sgw.service.AuthControlService;
import com.hp.bon.sgw.service.ConfigListener;
import com.hp.bon.sgw.service.ConfigService;
import com.hp.bon.sgw.service.FluxControlService;
import com.hp.bon.sgw.service.RSASignService;
import com.hp.bon.sgw.service.SGWCapabilityReqXMLValidator;
import com.hp.bon.sgw.start.SpringContext;
import com.hp.bon.sgw.threads.MessageDetailCacheManager;
import com.hp.bon.sgw.util.Comutils;
import com.hp.bon.sgw.util.dcc.DccAvpHelper;
import com.hp.bon.sgw.wh.bean.BusinessRecordPort;
import com.hp.bon.sgw.wh.bean.TInterfacePassword;
import com.hp.bon.sgw.wh.bean.tmall.WingBalanceQuery;
import com.hp.bon.sgw.wh.channel.common.BizConsts;
import com.hp.bon.sgw.wh.channel.handler.OutBlockUpHandle;
import com.hp.bon.sgw.wh.channel.handler.RechargeExtractHandle;
import com.hp.bon.sgw.wh.channel.handler.RechargeHandle;
import com.hp.bon.sgw.wh.channel.outside.OutApiBizProcedure;
import com.hp.bon.sgw.wh.mml.parser.XmlMessageParserInfo;
import com.hp.bon.sgw.wh.service.TYConfigService;
import com.hp.bon.sgw.wh.service.TmallLogDao;
import com.hp.bon.sgw.wh.service.UserResourceConfigService;
import com.hp.bon.sgw.wh.service.WHConfigService;
import com.hp.bon.sgw.wh.utils.StringUtil;
import com.hp.bon.sgw.wh.utils.ThreeDESKeyParam;
import com.ocs.client.CyclesQueryRequest;
import com.ocs.client.CyclesQueryResponse;
import com.ocs.client.CyclesRenewRequest;
import com.ocs.client.CyclesRenewResponse;

import bis.srt.uvc.webservice.UvcSoapForOcsServiceProxy;
import boss.service.pay.PayOtherLatn.PayOtherLatnProxy;
import boss.service.pay.client.OweItem;
import boss.service.pay.client.PayBlackOweRequest;
import boss.service.pay.client.PayBlackOweResponse;
import boss.service.pay.client.QueryBlackOweRequest;
import boss.service.pay.client.QueryBlackOweResponse;
import boss.service.web.client.CancelOrderChargeRequest;
import boss.service.web.client.CancelOrderChargeResponse;
import boss.service.web.client.CancelOrderChargeResponseItem;
import boss.service.web.client.CheckOrderChargeRequest;
import boss.service.web.client.CheckOrderChargeResponse;
import boss.service.web.client.CheckOrderChargeResponseItem;
import boss.service.web.client.QueryChargeSceneRequest;
import boss.service.web.client.QueryChargeSceneResponse;
import boss.service.web.webservice.BossServicePortTypeProxy;
import boss.service.ygz.client.DrawNetInvoiceRequest;
import boss.service.ygz.client.DrawNetInvoiceResponse;
import boss.service.ygz.client.PrestoreSpecialFunRequest;
import boss.service.ygz.client.PrestoreSpecialFunResponse;
import boss.service.ygz.client.PushNetInvoiceRequest;
import boss.service.ygz.client.PushNetInvoiceResponse;
import boss.service.ygz.client.QueryNetInvoiceRequest;
import boss.service.ygz.client.QueryNetInvoiceResponse;
import boss.service.ygz.client.QueryNetInvoiceResponseItem;
import boss.service.ygz.webservice.BossServicePortTypeYGZProxy;
import net.sf.json.JSONObject;

@Path("/")
public class RenewChannel implements Container, ConfigListener, IChannel {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LoggerFactory
			.getLogger(RenewChannel.class);
	static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	private HttpClient httpClient;
	protected ConfigService confSrv;
	private int maxLinkCount;
	static JAXBContext jc = null;
	private boolean replaceRealm;
	private String standardWSReqPath = "/ws/SGWService";
	private String standardHttpReqPath = "/http/call";
	private int TIMEOUT = 11203;
	
	private OutApiBizProcedure outApiBizProcedure;

	private WHConfigService whConfigService;
	private UserResourceConfigService userResourceConfigService ;
	private TYConfigService tyConfigService;
	private ContainerServer server = null;

	private String AdslCycleUrlWH = "";
	private String AdslCycleUrlHB = "";
	private String  HighCostHquery= "";
	private String IS_WD = "1001";
	private String IS_WH = "027";
	private String jf3_flag = "";
	private String jf3_area_code ="";
	private String jf3_latn_id ="";

	private String  QueryChargeSceneWH= "";
	private String  QueryChargeSceneHB= "";
	
	private String RechargeExtractURL="";
	private String RechargeExtractQueryURL="";
	
	private String  QueryBlackOweWH= "";
	private String  QueryBlackOweHB= "";
	
	private String  QueryNetInvoiceWH= "";
	private String  QueryNetInvoiceHB= "";
	
	private String  QueryNetInvoiceWHjf3= "";
	private String  QueryNetInvoiceHBjf3= "";
	
	private String  OrderChargeURL= "";
	private String  OrderChargeURLHB= "";
	
	
	private String  PayBlackOweWH= "";
	private String  PayBlackOweHB= "";
	
	private String QueryFluxCoverWH = "";
	private String QueryFluxCoverHB = "";
	
	private String QueryFluxRecleanWH = "";
	private String QueryFluxRecleanHB = "";
	
	private String OutBlockUpWH = "";
	private String OutBlockUpHB = "";
	
	private String QueryStopNetWH = "";
	private String QueryStopNetHB = "";
	
	private String QueryStopNetWHjf3 = "";
	private String QueryStopNetHBjf3 = "";
	
	private String QueryBlackOweWHjf3 = "";
	private String QueryBlackOweHBjf3 = "";
	
	private String PayBlackOweWHjf3 = "";
	private String PayBlackOweHBjf3 = "";
	
	private String PrestoreWH = "";
	private String PrestoreHB = "";
	
	private static Element OWE_ITEM;
	
	private static Element OWE_ITEM_EXT;
	
	private String tmallFlow_url= "";
	//
	protected RSASignService rsaSignService;

	static XMLInputFactory inputFactory = XMLInputFactory.newInstance();

	static {
		try {
			jc = JAXBContext.newInstance("cn.chinatelecom.sgw.soap");
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

	protected final Set<String> monitorConfKeys = new HashSet<String>();
	private SGWChannel channel;

	public RenewChannel(SGWChannel channel) {
		this.channel = channel;
		confSrv = SpringContext.getInstance().getConfigService();
		confSrv.addConfigListener(this);
		try {
			whConfigService = SpringContext.getApplicationContext().getBean(
					WHConfigService.class);
            userResourceConfigService= SpringContext.getApplicationContext().getBean(
                    UserResourceConfigService.class);
		} catch (Exception e) {
			e.getMessage();
		}
		try {
			tyConfigService = SpringContext.getApplicationContext().getBean(
					TYConfigService.class);
		} catch (Exception e) {
			e.getMessage();
		}
		
		AdslCycleUrlWH = whConfigService.getValue("AdslCycleUrlWH", "");
		AdslCycleUrlHB = whConfigService.getValue("AdslCycleUrlHB", "");
		
		//返销校验和返销URL
		OrderChargeURL=whConfigService.getValue("OrderChargeURL", "");
		OrderChargeURLHB=whConfigService.getValue("OrderChargeURLHB", "");
		
		//高额查询
		HighCostHquery=whConfigService.getValue("HighCostHquery", "");
		
		//综合查询武电
		QueryChargeSceneWH=whConfigService.getValue("QueryChargeSceneWH", "");
		//综合查询非武电
		QueryChargeSceneHB=whConfigService.getValue("QueryChargeSceneHB", "");
		
		//翼支付充值不可提现
		RechargeExtractURL=whConfigService.getValue("RechargeExtractURL", "");
		//翼支付充值不可提现查询
		RechargeExtractQueryURL=whConfigService.getValue("RechargeExtractURL", "");
		
		
		//拆机用户欠费查询武电
		QueryBlackOweWH=whConfigService.getValue("QueryBlackOweWH", "");
		//拆机用户欠费查询非武电
		QueryBlackOweHB=whConfigService.getValue("QueryBlackOweHB", "");
		//拆机用户欠费查询  20191018调整后 
		QueryBlackOweWHjf3 = whConfigService.getValue("QueryBlackOweWHjf3", "");
		QueryBlackOweHBjf3 = whConfigService.getValue("QueryBlackOweHBjf3", "");
		//电子发票查询武电
		QueryNetInvoiceWH=whConfigService.getValue("QueryNetInvoiceWH", "");
		//电子发票查询非武电
		QueryNetInvoiceHB=whConfigService.getValue("QueryNetInvoiceHB", "");
		//2.2.2.3电子发票  20191018调整后
		QueryNetInvoiceWHjf3=whConfigService.getValue("QueryNetInvoiceWHjf3", "");
		QueryNetInvoiceHBjf3=whConfigService.getValue("QueryNetInvoiceHBjf3", "");
		
		//拆机用户缴费武电
		PayBlackOweWH=whConfigService.getValue("PayBlackOweWH", "");
		
		//拆机用户缴费非武电
		PayBlackOweHB=whConfigService.getValue("PayBlackOweHB", "");
		
		//拆机用户黑名单缴费  20191018调整后
		PayBlackOweWHjf3=whConfigService.getValue("PayBlackOweWHjf3", "");
		PayBlackOweHBjf3=whConfigService.getValue("PayBlackOweHBjf3", "");
		
		//停开机武电
		OutBlockUpWH = whConfigService.getValue("OutBlockUpWH", "");
		
		//停开机非武电
		OutBlockUpHB = whConfigService.getValue("OutBlockUpHB", "");
		
		//停开机武电
		QueryStopNetWH = whConfigService.getValue("QueryStopNetWH", "");
		
		//停开机非武电
		QueryStopNetHB = whConfigService.getValue("QueryStopNetHB", "");
		//断网查询  20191018调整后
		QueryStopNetWHjf3 = whConfigService.getValue("QueryStopNetWHjf3", "");
		QueryStopNetHBjf3 = whConfigService.getValue("QueryStopNetHBjf3", "");
		
		//流量回溯查询武电
		QueryFluxCoverWH = whConfigService.getValue("QueryFluxCoverWH", "");
		
		//流量回溯查询非武电
		QueryFluxCoverHB = whConfigService.getValue("QueryFluxCoverHB", "");
		
		//流量回溯轨迹查询武电
		QueryFluxRecleanWH = whConfigService.getValue("QueryFluxRecleanWH", "");
		
		//流量回溯轨迹查询非武电
		QueryFluxRecleanHB = whConfigService.getValue("QueryFluxRecleanHB", "");
		tmallFlow_url = whConfigService.getValue("tmallflux.url","");
		
		//预存专款接口武电
		PrestoreWH=whConfigService.getValue("PrestoreWH", "");
		//预存专款接口非武电
		PrestoreHB=whConfigService.getValue("PrestoreHB", "");
		
		
//		 Timer _timer = new Timer("DelayTask-" + channel.toString(), true);
		// _timer.schedule(new DelayTask(), 1000,1000);
	}

	// private DelayService delayService;

	public void start() {
		logger.info("start soap channel:" + channel.toString() + " ...");
		monitorConfKeys.add(SysParamBean.KEY_BUSINESS_max_conn);
		this.loadParams();
		String key = "sgw.soapchannel.thread.max";
		int maxThreads = confSrv.getIntValue(key, 50);
		logger.info(key + " :" + maxThreads);
		String endPoint = this.channel.getUri();
		if (endPoint == null) {
			logger.warn("channel dont't defined ws addr");
			return;
		}
		logger.info("start sgw webservice server portal at " + endPoint);
		// delayService = new DelayService();
		// delayService.setName("DelayService-" + channel.getChannelHost());
		// delayService.start();
	    
		
		// 初始化对外请求新帐务中心流程类，主要处理功能：对外计费web接口
	    outApiBizProcedure = OutApiBizProcedure.instance();
	    logger.info("outApiBizProcedure init successfull.");
	    
	    
		try {
			URL srvURL = new URL(endPoint);
			int port = srvURL.getPort();
			if (port == -1) {
				port = 8080;
			}
			String host = srvURL.getHost();
			if (host.equals("127.0.0.1") || host.equalsIgnoreCase("localhost")) {
				host = "0.0.0.0";
			}
			server = new ContainerServer(this, maxThreads);

			Connection connection = new SocketConnection(server);
			SocketAddress address = new InetSocketAddress(host, port);
			connection.connect(address);
			collector = ((ContainerSelector) ((ContainerProcessor) server
					.getProcessor()).getSelector()).getCollect().getQueue();
			executor = ((ContainerSelector) ((ContainerProcessor) server
					.getProcessor()).getSelector()).getExecutor().getQueue();

			this.channel.setStatus(NodeStatus.ON_LINE);
			confSrv.updateChannelStatus2DB(this.channel.getId(),
					NodeStatus.ON_LINE);
		} catch (IOException e) {
			logger.error("start soap channel " + this.channel.toString()
					+ " err " + e);
		}

	}

	ThreadPoolExecutor executor;
	ThreadPoolExecutor collector;

	public static void directAck(XmlMessage ack, PrintStream responseStream)
			throws Exception {
		String orinData = ack.getDATA();
		String dataStr = (orinData == null || orinData == null) ? orinData
				: "<![CDATA[" + orinData + "]]>";
		String errMsg = ack.getDS();
		errMsg = (errMsg != null) && (errMsg.indexOf('&') == -1)
				&& (errMsg.indexOf('>') == -1) && (errMsg.indexOf('<') == -1) ? errMsg
				: StringEscapeUtils.escapeXml(errMsg);
		String respXML = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><ns3:SgwQueryAck xmlns:ns3=\"http://www.chinatelecom.cn/SGW/SOAP\"><MID>"
				+ ack.getMID()
				+ "</MID><REPTAG>0</REPTAG><RTT>"
				+ ack.getRTT()
				+ "</RTT><SIG>"
				+ ack.getSIG()
				+ "</SIG><RC>"
				+ ack.getRC()
				+ "</RC><DS>"
				+ errMsg
				+ "</DS><DATA>"
				+ dataStr
				+ "</DATA></ns3:SgwQueryAck></SOAP-ENV:Body></SOAP-ENV:Envelope>";
		responseStream.write(respXML.getBytes("UTF-8"));
		responseStream.close();
		if (logger.isInfoEnabled()) {
			logger.info("http response  " + respXML);
		}
	}


	public static XmlMessage createERRAnwser(String msgID, int retCode,
			String errMsg) {
		XmlMessage ack = new XmlMessage(false);
		ack.setMID(msgID);
		ack.setRTT(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
				.currentTimeMillis()));
		ack.setRC(Integer.toString(retCode));
		ack.setDS(errMsg);
		return ack;
	}

	/**
	 * 将xml格式的字符串转换成Map对象
	 * 
	 * @param xmlStr
	 *            xml格式的字符串
	 * @return Map对象
	 * @throws Exception
	 *             异常
	 */
	public static Map<String, Object> xmlStrToMap(String xmlStr)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		// 将xml格式的字符串转换成Document对象
		Document doc = DocumentHelper.parseText(xmlStr);
		// 获取根节点
		Element root = doc.getRootElement();
		// 获取根节点下的所有元素
		List children = root.elements();
		// 循环所有子元素
		if (children != null && children.size() > 0) {
			for (int i = 0; i < children.size(); i++) {
				Element child = (Element) children.get(i);
				map.put(child.getName(), child.getTextTrim());
				if (child.getName().equals("returnList")) {
					for (int j = 0; j < child.elements().size(); j++) {
						Element child1 = (Element) child.elements().get(j);
						map.put(child1.getName(), child1.getTextTrim());
						
						if (child1.getName().equals("returnInfo")) {
							for (int k = 0; k < child1.elements().size(); k++) {
								Element child2 = (Element) child1.elements().get(k);
								map.put(child2.getName(), child2.getTextTrim());
							}
						}
						
						
					}
				}
			}
		}
		return map;
	}
	/**
	 * 将xml格式的字符串转换成Map对象
	 * 
	 * @param xmlStr
	 *            xml格式的字符串
	 * @return Map对象
	 * @throws Exception
	 *             异常
	 */
	
	public static Map<String, Object> xmlStrToMapForGet(String xmlStr)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		// 将xml格式的字符串转换成Document对象
		Document doc = DocumentHelper.parseText(xmlStr);
		// 获取根节点
		Element root = doc.getRootElement();
		// 获取根节点下的所有元素
		List children = root.elements();
		// 循环所有子元素
		if (children != null && children.size() > 0) {
			for (int i = 0; i < children.size(); i++) {
				Element child = (Element) children.get(i);
				map.put(child.getName(), child.getTextTrim());
				if (child.getName().equals("returnList")) {
					for (int j = 0; j < child.elements().size(); j++) {
						Element child1 = (Element) child.elements().get(j);
						map.put(child1.getName(), child1.getTextTrim());
						
						if (child1.getName().equals("returnInfo")) {
							for (int k = 0; k < child1.elements().size(); k++) {
								Element child2 = (Element) child1.elements().get(k);
								map.put(child2.getName(), child2.getTextTrim());
								
								if (child2.getName().equals("returnMessage")) {
									for (int w = 0; w < child2.elements().size(); w++) {
										Element child3 = (Element) child2.elements().get(w);
										map.put(child3.getName(), child3.getTextTrim());
									}
								}
							}
						}
						
						
					}
				}
			}
		}
		return map;
	}
	
	
	public static Map<String, Object> xmlStrToMaps(String Str) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		// destinationId=02718971209827@ADSL,minExpDate=201606,requestId=13343421724,requestTime=2016060630,Area_Code=027
		//transactionId=1012300000000201608011722470908,busiTranId=1012300000000201608011722470908,appId=60000052,channelId=113,signCode=SVP320052,capInstId=10123,rtnDataFormatType=XML,contentId=1,regionId=1001,staffCode=hb43235,accNbr=18986137973,pricePlanId=220245,actionType=A
		String[] tmpValues = Str.split(",");

		for (int index = 0; index < tmpValues.length; index++) {
			String tv = tmpValues[index];
			tv = tv.trim();
			if (tv == null) {
				continue;
			}

			String[] zu = tv.split("=");
			map.put(zu[0], zu[1]);
		}
		return map;
	}

	// SOAP
	protected String convertResponseString(XmlMessage ack) {
		String orinData = ack.getDATA();
		String dataStr = (orinData == null || orinData == null) ? orinData
				: "<![CDATA[" + orinData + "]]>";
		String errMsg = ack.getDS();
		logger.info("errMsg----:"+errMsg);
		errMsg = (errMsg != null) && (errMsg.indexOf('&') == -1)
				&& (errMsg.indexOf('>') == -1) && (errMsg.indexOf('<') == -1) ? errMsg
				: StringEscapeUtils.escapeXml(errMsg);
		StringBuilder respXML = new StringBuilder();
		respXML.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><ns3:SgwQueryAck xmlns:ns3=\"http://www.chinatelecom.cn/SGW/SOAP\"><MID>");
		respXML.append(ack.getMID());
		respXML.append("</MID><REPTAG>0</REPTAG><RTT>");
		respXML.append(ack.getRTT());
		respXML.append("</RTT><SIG>");
		respXML.append(ack.getSIG());
		respXML.append("</SIG><RC>");
		respXML.append(ack.getRC());
		respXML.append("</RC><DS>");
		respXML.append(errMsg);
		respXML.append("</DS>");
		respXML.append("<DATA>");
		respXML.append(dataStr);
		respXML.append("</DATA></ns3:SgwQueryAck></SOAP-ENV:Body></SOAP-ENV:Envelope>");
		return respXML.toString();
	}

	/**
	 * 取优先级
	 * 
	 * @param serviceCtxID
	 *            能力
	 * @param neHostID
	 *            网元
	 * @param userName
	 *            用户
	 * @return
	 */
	public int calcMsgPrority(CallParam callParam) {
		int priority = Constants.PRIORITY_DEFAULT;
		if (callParam.getCapabilityBean() == null) {
			if (logger.isDebugEnabled()) {
				logger.debug("can't find priority define for: "
						+ callParam.getUserName() + ","
						+ callParam.getCapability());
			}
		} else {
			priority = callParam.getCapabilityBean().getPriority();
		}
		if (logger.isDebugEnabled()) {
			logger.debug("message priority For NE " + callParam.getUserName()
					+ " capability:" + callParam.getCapability() + " is "
					+ priority);
		}
		return priority;
	}
	private String parseNetListReturn(String representation) throws Exception {
		StringBuffer data = new StringBuffer();
		Document doc = DocumentHelper.parseText(representation);
		Element root = doc.getRootElement();
		Element returnE = root.element("Body").element("HighCostHqueryResponse").element("return");
		returnE.setName("Service_Information");
		String xmlStr = returnE.asXML();
    	data.append(xmlStr);
    	data.insert(21, "<Result>0</Result>");
    	logger.info("qweqweqwewqwe" + xmlStr);
    	logger.info("data.toString()" + data.toString());
		return data.toString();
	}
	
	private String parseNetListReturnObur(String representation) throws Exception {
		StringBuffer data = new StringBuffer();
		Document doc = DocumentHelper.parseText(representation);
		Element root = doc.getRootElement();
		Element returnE = root.element("Body").element("OutBlockUpResponse");
		String xmlStr = returnE.asXML();
    	data.append(xmlStr);
		return data.toString();
	}
	
	private  String parseQueryStopReturnObur(String representation) throws Exception {
		logger.info("representation" + representation);
		StringBuffer data = new StringBuffer();
		Document doc = DocumentHelper.parseText(representation);
		Element root = doc.getRootElement();
		logger.info("root" + root.toString());
		logger.info("root" + root.getText());
		Element returnE = root.element("Body").element("QueryStopNetResponse");
		String xmlStr = returnE.asXML();
    	data.append(xmlStr);
		return data.toString();
	}
	
	private Map<String, String> parseQueryFluxCoverNetListReturnObur(String representation) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		Document doc = DocumentHelper.parseText(representation);
		Element root = doc.getRootElement();
		Element returnE = root.element("Body").element("QueryFluxCoverResponse");
		String xmlStr = returnE.asXML();
		String  respStr = "<QueryFluxCoverResponse xmlns=\"http://web.service.boss/client/\">(.*)</QueryFluxCoverResponse>";
		Pattern pattern = Pattern.compile(respStr);
		Matcher matcher = pattern.matcher(xmlStr);
        String interceptRespStr = "";
		while (matcher.find()) {
			interceptRespStr = matcher.group(1);
		}
		map.put(xmlStr, interceptRespStr);
		return map;
	}
	
	private Map<String, String> parseQueryFluxRecleanNetListReturnObur(String representation) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		Document doc = DocumentHelper.parseText(representation);
		Element root = doc.getRootElement();
		Element returnE = root.element("Body").element("QueryFluxRecleanResponse");
		String xmlStr = returnE.asXML();
		String  respStr = "<QueryFluxRecleanResponse xmlns=\"http://web.service.boss/client/\">(.*)</QueryFluxRecleanResponse>";
		Pattern pattern = Pattern.compile(respStr);
		Matcher matcher = pattern.matcher(xmlStr);
        String interceptRespStr = "";
		while (matcher.find()) {
			interceptRespStr = matcher.group(1);
		}
		map.put(xmlStr, interceptRespStr);
		return map;
	}
	private static String parseRechargeExtractReturn(String representation) throws Exception {
		logger.info("representation" + representation);
		StringBuffer data = new StringBuffer();
		Document doc = DocumentHelper.parseText(representation);
		logger.info("doc" + doc.asXML());
		Element root = doc.getRootElement();
		logger.info("root" + root.asXML());
		Element returnE = root.element("Envelope").element("out").element("PayPlatResponseParameter");
		returnE.setName("Service_Information");
		String xmlStr = returnE.asXML();
    	data.append(xmlStr);
    	data.insert(21, "<Result>0</Result>");
    	logger.info("qweqweqwewqwe" + xmlStr);
    	logger.info("data.toString()" + data.toString());
		return data.toString();
	}

	/**
	 * 检查调用参数是否有效，是否可以通过验证
	 * 
	 * @param bonParam
	 * @return
	 */
	public int checkBonCallParamForSoap(CallParam callParam,
			StringBuilder errMsg) {
		XmlMessage request = (XmlMessage) callParam.getRequest();
		String uid = callParam.getUserName();
		if ((uid == null) || uid == null || uid.length() > 64) {
			errMsg.append("UID is illegal");
			return Constants.ResultCode.VALUE_ERROR;
		}
		Node node = SpringContext.getInstance().getConfigService()
				.getNodeByName(callParam.getUserName());
		// 检查 用户名
		if (node == null) {
			errMsg.append("AuthFailed: UserName not found");
			return Constants.ResultCode.USER_NOT_EXIST;
		}
		callParam.setFromNode(node);

		// 处理DATA元素
		String rawData = request.getDATA();
		if (rawData == null) {
			errMsg.append("Missing \"DATA\" Tag.");
			return Constants.ResultCode.MISSING_TAG;
		}
		try {
			Document doc = Comutils.parseText(rawData);
			request.setDataElement(doc.getRootElement());
		} catch (Exception e) {
			errMsg.append("Invalid request DATA format ,not valid xml "
					+ e.toString());
			return Constants.ResultCode.UNKNOW_TAG;
		}

		// //处理INFO元素
		// Element infoRootElement = null;
		// try {
		// if(request.isUnified() && request instanceof UnifiedXmlMessage){
		// UnifiedXmlMessage unifiedRequest = (UnifiedXmlMessage)request;
		// String rawInfos = unifiedRequest.getInfos();
		// if (rawInfos == null) {
		// errMsg.append("Missing \"INFO\" Tag.");
		// return Constants.ResultCode.MISSING_TAG;
		// }
		// Document doc = Comutils.parseText(rawInfos);
		// infoRootElement = doc.getRootElement();
		// }
		// } catch (Exception e) {
		// errMsg.append("Invalid request INFO format ,not valid xml " +
		// e.toString());
		// return Constants.ResultCode.UNKNOW_TAG;
		// }

		int reqByts = 0;
		byte[] reqDataBytes = null;
		try {
			reqDataBytes = rawData.getBytes("ISO-8859-1");
		} catch (UnsupportedEncodingException e2) {
			logger.error("encoding failed " + e2);
		}
		// 检查Pertri网状态，是否处于停工状态
		if (!SpringContext.getInstance().getPertriBean().canHandleNewRequest()) {
			String inf = "ignore any new request , for system is in status of "
					+ SpringContext.getInstance().getPertriBean()
							.getPertiStatusName();
			logger.info(inf);
			errMsg.append(inf);
			return Constants.ResultCode.SYSTEM_BUSY;
		}
		String scid = callParam.getServiceContextId();
		if (scid == null || scid.equals("")) {
			errMsg.append("scid is null");
			return Constants.ResultCode.UNKNOW_TAG;
		} else if (!scid.contains("@")) {
			errMsg.append("scid is illegal");
			return Constants.ResultCode.UNKNOW_TAG;
		}
		AuthResult autResult = AuthControlService.getInstance().authWSAccess(
				callParam, reqDataBytes, true);
		if (autResult.getCode() != AuthResult.SUCCESS) {
			errMsg.append(autResult.getHint());
			return autResult.getCode();
		}
		String capability = DccAvpHelper.getCapability(scid);
		int priority = this.calcMsgPrority(callParam);
		// CPU 超负荷处理
		if (SpringContext.getInstance().getCPUOverloadBean()
				.dropRequest(priority, callParam.getSessionId(), capability)) {
			errMsg.append("cpu overload, wait a moment please.");
			return Constants.ResultCode.SYSTEM_BUSY;
		}
		// 拥塞控制处理
		if (CongestionBean.getInstance().dropRequest(priority,
				callParam.getSessionId(), capability)) {
			errMsg.append("system congestioned ,please dont't send request anymore ");
			return Constants.ResultCode.SYSTEM_BUSY;
		}
		// 检查是否流量超标
		int fluxRetCode = FluxControlService.getInstance().checkUserFlux(
				callParam, reqByts);
		if (fluxRetCode == Constants.ResultCode.FLUX_DISCONNECT) {
			errMsg.append("not allowed anymore , reached traffic  limit ,please wait some minutes ");
			return Constants.ResultCode.FLUX_DISCONNECT;
		} else if (fluxRetCode == Constants.ResultCode.MESSAGE_SIZE_OVER) {// 单个包大小超标
			errMsg.append("message size too large ");
			return Constants.ResultCode.MESSAGE_SIZE_OVER;
		}

		// 预处理服务链，包括内容过滤、根据关键字流量控制等
		// ProcessResult processResult =
		// ServiceChain.getInstance().doPreServices(callParam);
		// if(processResult != null && processResult.getRet() !=
		// ResultCode.SUCCESS)
		// {
		// errMsg.append(processResult.getErrMsg());
		// return processResult.getRet();
		// }
		// 按能力进行特定错码限流,检查是否流量超标
		// int fluxScIdRetCode =
		// FluxControlByRcService.getInstance().checkRcFlux(callParam, reqByts);
		// if(fluxScIdRetCode == Constants.ResultCode.FLUX_CAPA_RESULT)
		// {
		// errMsg.append("not allowed anymore , reached capability result code traffic limit ,please wait some minutes ");
		// return Constants.ResultCode.FLUX_CAPA_RESULT;
		// }
		// 关键字统计
		// FluxControlService.getInstance().doWatchKey(callParam.getServiceContextId(),
		// callParam.getAsynHandler().getProtocolType(),
		// callParam.getRequest());
		// String result =
		// BlacklistMonitorThread.getInstance().checkBlackList(callParam);
		// if (result != null) {
		// errMsg.append("usr in blacklist:" + result);
		// return Constants.ResultCode.Usr_in_Blacklist;
		// }

		// Request的XML DATA 数据校验
		StringBuilder xmlValidatHint = new StringBuilder();
		int errCode = SGWCapabilityReqXMLValidator.getInstance()
				.validateRequest(capability, request.getDataElement(),
						xmlValidatHint);
		if (errCode != 0) {
			errMsg.append("Validate Request DATA Failed:"
					+ xmlValidatHint.toString());
			return errCode;
		}
		// Request的XML INFO 数据校验
		// if (infoRootElement != null) {
		// xmlValidatHint.delete(0, xmlValidatHint.length());
		// errCode =
		// SGWCapabilityReqXMLValidator.getInstance().validateRequest(capability+"@info",
		// infoRootElement, xmlValidatHint);
		// if (errCode != 0) {
		// errMsg.append("Validate Request INFO Failed:" +
		// xmlValidatHint.toString());
		// return errCode;
		// }
		// }
		// SGW填写签名信息
		// SGW填写签名信息
		// if (infoRootElement != null) {
		// return SgwCAHelper.fillCAInfos(request, infoRootElement, errMsg);
		// }
		return Constants.ResultCode.SUCCESS;
	}

	private boolean doStandardWSCall(XmlMessage reqXmlMessage, PrintStream body)
			throws Exception {

		String serviceCtxID = reqXmlMessage.getSCID();
		if (replaceRealm
				&& !serviceCtxID.endsWith(confSrv.getRealmWithoutAreaCode())) {
			serviceCtxID = DccAvpHelper.replaceSrvCtxID(serviceCtxID,
					confSrv.getRealmWithoutAreaCode());
			reqXmlMessage.setSCID(serviceCtxID);
		}
		BaseWSCallHandler asynHandler = new BaseWSCallHandler(body);
		CallParam callParam = new CallParam(reqXmlMessage.getMID(),
				reqXmlMessage.getSCID(), reqXmlMessage, reqXmlMessage.getUID(),
				asynHandler);
		// callParam.setType(4);//4老SOAP请求的老报文或老DCC3.0 CCR

		MessageDetail detail = new MessageDetail();
		detail.setBusinessCallId(callParam.getBussinessCallId());
		detail.setSessionId(callParam.getSessionId());
		detail.setServiceContextId(callParam.getServiceContextId());
		detail.setMessageType(MessageType.WSR);
		detail.setDetails(reqXmlMessage.getDATA());
		detail.setMsgTime(new Date(reqXmlMessage.getMsgTime()));
		detail.setOpType("recv");
		detail.setHostId(callParam.getUserName());
		MessageDetailCacheManager.getInstance().add(detail);

		// 鉴权
		StringBuilder errMsg = new StringBuilder();
		int result = checkBonCallParamForSoap(callParam, errMsg);
		if (result != Constants.ResultCode.SUCCESS) {
			callParam.setRetCode(result);
			callParam.setResultMsg(errMsg.toString());
			asynHandler.onCallResult(callParam);
			return false;
		} else {
			return true;
		}

		// 延时处理
		// Modify by ZT 2013-07-01 15:22:50
		// DelayForwardConfig blockBean =
		// confSrv.getRequestBlockMap(callParam.getServiceContextId(),
		// callParam.getUserName());
		// if (blockBean == null) {
		// String cap =
		// DccAvpHelper.getCapability(callParam.getServiceContextId());
		// blockBean = confSrv.getRequestBlockMap(cap, callParam.getUserName());
		// }
		//
		// if (blockBean != null && blockBean.getSleepTime() > 0) {
		// long delayMills = System.currentTimeMillis() +
		// blockBean.getSleepTime();
		// delayService.delay(delayMills, callParam, executor);
		// //logger.info(callParam.getSessionId() + " will forward after " +
		// blockBean.getSleepTime() + " ms");
		// } else {

		// }
	}

	public void handle(Request request, Response response) {
		logger.info("RenewChannel receive request from "
				+ request.getClientAddress() + "; " + request.toString());
		long receiveTime = System.currentTimeMillis();
		String IP = request.getClientAddress().getAddress().getHostAddress();
		PrintStream body = null;
		try {
			body = response.getPrintStream();
			response.set("Content-Type", "text/xml;charset=utf-8");
			response.set("Server", "HP  Asyn WS WebServer )");
			response.setDate("Date", receiveTime);
			response.setDate("Last-Modified", receiveTime);
			ContentType cntType = request.getContentType();
			if (cntType == null) {
				body.println("invalid request Content type is null");
				body.close();
				return;
			}
			cntType.setCharset(Comutils.fixContentCharSet(cntType.getCharset()));
			String reqContent = request.getContent();
			logger.info("======reqContent======" + reqContent);

			// parse Request, transfer to XmlMessage
			XmlMessage reqXmlMessage = null;
			try {
				reqXmlMessage = XmlMessageParserInfo.parseWSRequest(inputFactory, request.getContent());
				reqXmlMessage.setMsgTime(receiveTime);
				reqXmlMessage
						.setIp(request.getClientAddress() != null ? request
								.getClientAddress().getAddress()
								.getHostAddress() : "");

				// 检查是否走新流程，并处理新流程，若返回[TYPE_ORIG_FLOW]则表示走老流程
				logger.info("start check new flow...");
				logger.info("doProcedure...");
				String flowRetCode = outApiBizProcedure.doProcedure(reqXmlMessage, request, response, receiveTime);
				if(!BizConsts.TYPE_ORIG_FLOW.equals(flowRetCode)) {
					logger.info("working on the new flow, and completely.");
					return;
				}
				logger.info("working on the old flow...");

				if (doStandardWSCall(reqXmlMessage, body)) {
					logger.info("====1111111111==reqXmlMessage.getSCID()======" + reqXmlMessage.getSCID());

					// 多账期宽带续费查询 外部平台发送可用余额和欠费查询请求
					if (reqXmlMessage.getSCID().equals(
							"CyclesQuery.ADSL@027.ctnbc-bon.net")) {
						logger.info("======CyclesQuery.ADSL.getDATA()======"
								+ reqXmlMessage.getDATA());

						Map<String, Object> map = xmlStrToMaps(reqXmlMessage
								.getDATA());
						String destinationId = (String) map
								.get("destinationId");
						String minExpDate = (String) map.get("minExpDate");
						String requestId = (String) map.get("requestId");
						String requestTime = (String) map.get("requestTime");
						String areaCode = (String) map.get("Area_Code");
						logger.info("======areaCode======" + areaCode);
						String url = null;
						if (areaCode.equals("027")) {
							url = AdslCycleUrlWH;
						} else {
							url = AdslCycleUrlHB;
						}
						logger.info("===============调用地址url============" + url);
						UvcSoapForOcsServiceProxy proxy = new UvcSoapForOcsServiceProxy(
								url);
						CyclesQueryRequest cqr = new CyclesQueryRequest();
						cqr.setDestinationId(destinationId);
						cqr.setMinExpDate(minExpDate);
						cqr.setRequestId(requestId);
						cqr.setRequestTime(requestTime);
						CyclesQueryResponse resp = proxy.cyclesQuery(cqr);

						String acctId = resp.getAcctId();
						logger.info("==============acctId==========" + acctId);
						String acctName = resp.getAcctName();
						logger.info("==============acctName==========" + acctName);
						int balanceTypeID = resp.getBalanceTypeID();
						logger.info("==============balanceTypeID==========" + balanceTypeID);
						String custPricePlanID = resp.getCustPricePlanID();
						logger.info("==============custPricePlanID==========" + custPricePlanID);
						int cycleCharge = resp.getCycleCharge();
						logger.info("==============cycleCharge==========" + cycleCharge);
						int cycleMonth = resp.getCycleMonth();
						logger.info("==============cycleMonth==========" + cycleMonth);
						int cyclesFlag = resp.getCyclesFlag();
						logger.info("==============cyclesFlag==========" + cyclesFlag);
						String effDate = resp.getEffDate();
						logger.info("==============effDate==========" + effDate);
						String errorMsg = resp.getErrorMsg();
						logger.info("==============errorMsg==========" + errorMsg);
						String expDate = resp.getExpDate();
						logger.info("==============expDate==========" + expDate);
						String normalCharge = resp.getNormalCharge();
						logger.info("==============normalCharge==========" + normalCharge);
						String pricePlanName = resp.getPricePlanName();
						logger.info("==============pricePlanName==========" + pricePlanName);
						String region_id = resp.getRegion_id();
						logger.info("==============region_id==========" + region_id);
						String responseId = resp.getResponseId();
						logger.info("==============responseId==========" + responseId);
						String responseTime = resp.getResponseTime();
						logger.info("==============responseTime==========" + responseTime);
						int returnCode = resp.getReturnCode();
						logger.info("==============returnCode==========" + returnCode);
						String servId = resp.getServId();
						logger.info("==============servId==========" + servId);
						Element serviceInformation = DocumentHelper
								.createElement("Service_Information");
						Element element = serviceInformation
								.addElement("Result");

						if (returnCode == 0) {

							element.setText(String.valueOf(returnCode));
							element = serviceInformation.addElement("acctId");
							if (acctId == null || acctId.equals("")) {
								element.setText("");
							} else {
								element.setText(acctId);
							}
							element = serviceInformation.addElement("acctName");
							if (acctName == null || acctName.equals("")) {
								element.setText("");
							} else {
								element.setText(acctName);
							}
							element = serviceInformation
									.addElement("balanceTypeID");
							element.setText(String.valueOf(balanceTypeID));
							element = serviceInformation
									.addElement("custPricePlanID");
							if (custPricePlanID == null
									|| custPricePlanID.equals("")) {
								element.setText("");
							} else {
								element.setText(custPricePlanID);
							}
							element = serviceInformation
									.addElement("cycleCharge");
							element.setText(String.valueOf(cycleCharge));
							element = serviceInformation
									.addElement("cycleMonth");
							element.setText(String.valueOf(cycleMonth));
							element = serviceInformation
									.addElement("cyclesFlag");
							element.setText(String.valueOf(cyclesFlag));
							element = serviceInformation.addElement("effDate");
							if (effDate == null || effDate.equals("")) {
								element.setText("");
							} else {
								element.setText(effDate);
							}
							element = serviceInformation.addElement("errorMsg");
							if (errorMsg == null || errorMsg.equals("")) {
								element.setText("");
							} else {
								element.setText(errorMsg);
							}
							element = serviceInformation.addElement("expDate");
							if (expDate == null || expDate.equals("")) {
								element.setText("");
							} else {
								element.setText(expDate);
							}
							element = serviceInformation
									.addElement("normalCharge");
							if (normalCharge == null
									|| normalCharge.equals("")
									|| normalCharge.length() == 0) {
								element.setText("");
							} else {
								element.setText(normalCharge);
							}
							element = serviceInformation
									.addElement("pricePlanName");
							if (pricePlanName == null
									|| pricePlanName.equals("")) {
								element.setText("");
							} else {
								element.setText(pricePlanName);
							}
							element = serviceInformation
									.addElement("region_id");
							if (region_id == null || region_id.equals("")) {
								element.setText("");
							} else {
								element.setText(region_id);
							}
							element = serviceInformation
									.addElement("responseId");
							if (responseId == null || responseId.equals("")) {
								element.setText("");
							} else {
								element.setText(responseId);
							}
							element = serviceInformation
									.addElement("responseTime");
							if (responseTime == null
									|| responseTime.equals("")) {
								element.setText("");
							} else {
								element.setText(responseTime);
							}
							element = serviceInformation
									.addElement("returnCode");
							element.setText(String.valueOf(returnCode));
							element = serviceInformation.addElement("servId");
							if (servId == null || servId.equals("")) {
								element.setText("");
							} else {
								element.setText(servId);
							}
						} else {
							element.setText(String.valueOf(returnCode));
							element = serviceInformation.addElement("errorMsg");
							if (errorMsg == null || errorMsg.equals("")) {
								element.setText("");
							} else {
								element.setText(errorMsg);
							}
						}
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(0);
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
						
						tmallLogDao.insertBusinessRecordPort(bean);
						
						logger.info("serviceInformation---"+serviceInformation.asXML());
						XmlMessage ack = new XmlMessage(true);
						ack.setMID(reqXmlMessage.getMID());
						ack.setREPTAG(0);
						ack.setRTT(String.valueOf(receiveTime));
						ack.setSIG(null);
						ack.setRC("0");
						ack.setDS("SUCCESS");
						ack.setDATA(serviceInformation.asXML());
						String respXML = convertResponseString(ack);
						logger.info("=======================respXML========================");
						logger.info(respXML);
						logger.info("=======================respXML========================");
						byte[] resps = respXML.getBytes("UTF-8");
						ack.setLength(resps.length);
						ack.setMsgTime(System.currentTimeMillis());
						body.write(resps);
						body.close();

						
					}
					//RechargeExtract.BestPay翼支付充值不可提现
					 else if (reqXmlMessage.getSCID().equals(
								"RechargeExtract.BestPay@027.ctnbc-bon.net")) {
							logger.info("======RechargeExtract.BestPay.getDATA()======"
									+ reqXmlMessage.getDATA());
							Map<String, Object> map = xmlStrToMaps(reqXmlMessage
									.getDATA());
							String productNo= (String) map.get("PRODUCTNO");
							String accountType = (String) map.get("ACCOUNTTYPE");
							String accountIdType = (String) map.get("ACCOUNTIDTYPE");
							String txndscpt = (String) map.get("TXNDSCPT");
							String txnAmount = (String) map.get("TXNAMOUNT");
							String feeFlag = (String) map.get("FEEFLAG");
							String feeAmt = (String) map.get("FEEAMT");
							String businessType = (String) map.get("BUSINESSTYPE");
							String txnType = (String) map.get("TXNTYPE");
							String supplyOrgCode = (String) map.get("SUPPLYORGCODE");
							String acceptOrgCode = (String) map.get("ACCEPTORGCODE");
							String acceptUid = (String) map.get("ACCEPTUID");
							String acceptAreaCode = (String) map.get("ACCEPTAREACODE");
							String acceptCityCode = (String) map.get("ACCEPTCITYCODE");
							String acceptChannel = (String) map.get("ACCEPTCHANNEL");
							String acceptSeqNo = (String) map.get("ACCEPTSEQNO");
							String acceptTransDate = (String) map.get("ACCEPTTRANSDATE");
							String acceptTransTime = (String) map.get("ACCEPTTRANSTIME");
							String terminalSeqNo="";
							if(map.get("TERMINALSEQNO")!=null&&!"".equals(map.get("TERMINALSEQNO"))){
								terminalSeqNo=map.get("TERMINALSEQNO").toString();
							}
							String inputTime = (String) map.get("INPUTTIME");
							String areaCode = (String) map.get("Area_Code");
							String staffId = (String) map.get("Staff_Id");
							String channelId = (String) map.get("Channel_Id");
							String siteId = (String) map.get("Site_Id");
							String operType = (String) map.get("Oper_Type");
							
							int a=(int)((Math.random()*9+1)*100000);
							long currentTime = System.currentTimeMillis();
							SimpleDateFormat formatter = new SimpleDateFormat("yyyymmddHH");
							Date date = new Date(currentTime);
							String time	=formatter.format(date);
							logger.info("======time======"+ time);
							
							
							StringBuffer para = new StringBuffer();
							
							para.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
							para.append("xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ");
							para.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
							para.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");
							para.append("<SOAP-ENV:Body> ");
							para.append("<m:dispatchCommand xmlns:m=\"http://control.ppcore.haobai.huateng.com\"> ");
							para.append("<m:in0>");
							para.append("200401|420000-TEST1-127.0.0.1|127.0.0.1|1.0");
							para.append("</m:in0> ");
							para.append("<m:in1> ");
							
							para.append("<![CDATA[");
							para.append("<PayPlatRequestParameter> ");
							para.append("<CTRL-INFO WEBSVRNAME=\"SGW\" WEBSVRCODE=\"200401\" APPFROM=\"420000-SGW-127.0.0.1\" KEEP=\""+time+String.valueOf(a)+"\"/> ");
							para.append("<PARAMETERS>");
							para.append("<PRODUCTNO>" + productNo + "</PRODUCTNO>");
							para.append("<ACCOUNTTYPE>" + accountType + "</ACCOUNTTYPE>");
							para.append("<TXNAMOUNT>" + txnAmount + "</TXNAMOUNT>");
							para.append("<FEEFLAG>" + feeFlag + "</FEEFLAG>");
							para.append("<FEEAMT>" + feeAmt + "</FEEAMT>");
							para.append("<BUSINESSTYPE>" + businessType + "</BUSINESSTYPE>");
							para.append("<TXNTYPE>" + txnType + "</TXNTYPE>");
							para.append("<SUPPLYORGCODE>" + supplyOrgCode + "</SUPPLYORGCODE>");
							para.append("<ACCEPTORGCODE>" + acceptOrgCode + "</ACCEPTORGCODE>");
							para.append("<ACCEPTAREACODE>" + acceptAreaCode + "</ACCEPTAREACODE>");
							para.append("<ACCEPTCITYCODE>" + acceptCityCode + "</ACCEPTCITYCODE>");
							para.append("<ACCEPTCHANNEL>" + acceptChannel + "</ACCEPTCHANNEL>");
							para.append("<ACCEPTSEQNO>" + acceptSeqNo + "</ACCEPTSEQNO>");
							para.append("<ACCEPTTRANSDATE>" + acceptTransDate + "</ACCEPTTRANSDATE>");
							para.append("<ACCEPTTRANSTIME>" + acceptTransTime + "</ACCEPTTRANSTIME>");
							para.append("<TERMINALSEQNO>" + terminalSeqNo + "</TERMINALSEQNO>");
							para.append("<INPUTTIME>" + inputTime + "</INPUTTIME>");
							para.append("</PARAMETERS>");
							para.append("</PayPlatRequestParameter>");
							para.append("]]> ");
							
							
							para.append("</m:in1> ");
							para.append("</m:dispatchCommand> ");
							para.append("</SOAP-ENV:Body> ");
							para.append("</SOAP-ENV:Envelope> ");
							
							logger.info("===============para.toString()============" + para.toString());
							String url  = RechargeExtractURL;
							logger.info("===============调用地址url============" + url);
							
							String result =postHttpReqTimeout(url, para.toString());
							
							logger.info("==============resp========" + result);
							
							if(result!=null&&(!"".equals(result)||"0".equals(result))){
								
								logger.info("==============成功========");
								
								
								String respss=result.replaceAll("&lt;", "<").replaceAll("&#xd;", "");
								String code="";
								if(!"0".equals(respss)){
									 code=respss.split("<RESPONSECODE>")[1].split("</RESPONSECODE>")[0];
								}
								
								
								if("000000".equals(code)||"0".equals(result)){
									logger.info("==============code========" + code);
									String dates="";
									//解析返回串
									if("0".equals(result)){
										 dates="<Result>0</Result><RESPONSECODE>000000</RESPONSECODE>";
									}else{
										 dates="<Result>0</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
									}
									
									BusinessRecordPort bean= new BusinessRecordPort();
									bean.setSessionId(reqXmlMessage.getMID());
									bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
											.currentTimeMillis()));
									bean.setRequestHost(reqXmlMessage.getUID());
									bean.setServiceContextId(reqXmlMessage.getSCID());
									bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
											.currentTimeMillis()));
									bean.setResult(0);
									TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
									
									tmallLogDao.insertBusinessRecordPort(bean);
									
									
									
									Element serviceInformation = DocumentHelper.createElement("Service_Information");
									Element element = serviceInformation.addElement("Area_Code");
									element.setText(areaCode);
									element = serviceInformation.addElement("Acc_Nbr");
									element.setText(productNo);
									element = serviceInformation.addElement("Block_Date");
									element.setText(acceptTransDate);
									element = serviceInformation.addElement("Staff_Id");
									element.setText(staffId);
									element = serviceInformation.addElement("Balance_Amount");
									element.setText(txnAmount);
									element = serviceInformation.addElement("Reverse_Amount");
									element.setText("0");
									element = serviceInformation.addElement("Channel_Id");
									element.setText(channelId);
									element = serviceInformation.addElement("Site_Id");
									element.setText(siteId);
									element = serviceInformation.addElement("Oper_Type");
									element.setText(operType);
									element = serviceInformation.addElement("Oper_Serial_Nbr");
									element.setText(acceptSeqNo);
									element = serviceInformation.addElement("Oper_serial");
									element.setText("	");
									WingBalanceQuery wingBalanceQuery = new WingBalanceQuery("", "", "", "", "", "", "");
									XmlMessage req = new XmlMessage(true);
									req.setIp(IP);
									req.setMsgTime(receiveTime);
									req.setMID(reqXmlMessage.getMID());
									req.setUID(reqXmlMessage.getUID());
									if(areaCode.equals("027")){
										req.setSCID("JfzsRechargeInfoSave.WH@027.ctnbc-bon.net");
									}else{
										req.setSCID("JfzsRechargeInfoSave.HB@027.ctnbc-bon.net");
									}
									req.setSIG(null);
									req.setREPTAG(0);
									req.setDATA(serviceInformation.asXML());
									req.setDataElement(serviceInformation);
									// new CallParam对象
									RechargeExtractHandle rechargeHandle = new RechargeExtractHandle(body,map,reqXmlMessage,IP,"","",wingBalanceQuery,tyConfigService.getValue("APP_CODE", ""),tyConfigService.getValue("IP", ""),tyConfigService.getValue("VERSION", ""),dates);
									CallParam callParam = new CallParam(req.getMID(), req.getSCID(),req, req.getUID(), rechargeHandle);
									BuzProcessorManager.getInstance().processRequest(callParam);
								}else{
									String dates="<Result>1</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
									BusinessRecordPort bean= new BusinessRecordPort();
									bean.setSessionId(reqXmlMessage.getMID());
									bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
											.currentTimeMillis()));
									bean.setRequestHost(reqXmlMessage.getUID());
									bean.setServiceContextId(reqXmlMessage.getSCID());
									bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
											.currentTimeMillis()));
									bean.setResult(1);
									bean.setResultCode(Integer.valueOf(respss.split("<RESPONSECODE>")[1].split("</RESPONSECODE>")[0]));
									TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
									
									tmallLogDao.insertBusinessRecordPort(bean);
									
									Element serviceInformation = DocumentHelper.createElement("Service_Information");
									Element element = serviceInformation.addElement("Area_Code");
									element.setText(areaCode);
									logger.info("==============areaCode========" + areaCode);
									element = serviceInformation.addElement("Acc_Nbr");
									element.setText(productNo);
									
									logger.info("==============productNo========" + productNo);
									element = serviceInformation.addElement("Block_Date");
									element.setText(acceptTransDate);
									logger.info("==============acceptTransDate========" + acceptTransDate);
									element = serviceInformation.addElement("Staff_Id");
									element.setText(staffId);
									logger.info("==============staffId========" + staffId);
									element = serviceInformation.addElement("Balance_Amount");
									element.setText(txnAmount);
									logger.info("==============txnAmount========" + txnAmount);
									element = serviceInformation.addElement("Reverse_Amount");
									element.setText("0");
									element = serviceInformation.addElement("Channel_Id");
									element.setText(channelId);
									logger.info("==============channelId========" + channelId);
									element = serviceInformation.addElement("Site_Id");
									element.setText(siteId);
									logger.info("==============siteId========" + siteId);
									element = serviceInformation.addElement("Oper_Type");
									element.setText(operType);
									logger.info("==============operType========" + operType);
									element = serviceInformation.addElement("Oper_Serial_Nbr");
									element.setText(acceptSeqNo);
									logger.info("==============acceptSeqNo========" + acceptSeqNo);
									element = serviceInformation.addElement("Oper_serial");
									element.setText("	");
									
									XmlMessage req = new XmlMessage(true);
									req.setIp(IP);
									req.setMsgTime(receiveTime);
									req.setMID(reqXmlMessage.getMID());
									req.setUID(reqXmlMessage.getUID());
									req.setSIG(null);
									req.setREPTAG(0);
									req.setDATA(dates);
									req.setDataElement(serviceInformation);
									
									String respXML = convertResponseString(req);
									logger.info("=======================respXML========================");
									logger.info(respXML);
									logger.info("=======================respXML========================");
									byte[] resps = respXML.getBytes("UTF-8");
									req.setLength(resps.length);
									req.setMsgTime(System.currentTimeMillis());
									body.write(resps);
									body.close();
								}
							}else{
								Element serviceInformationRecharge = DocumentHelper
										.createElement("Service_Information");
								Element elementRe = serviceInformationRecharge
										.addElement("Result");
								elementRe.setText("1");
								elementRe = serviceInformationRecharge.addElement("RESPONSECODE");
								elementRe.setText("17004");
								elementRe = serviceInformationRecharge.addElement("RESPONSECONTENT");
								elementRe.setText("");
								
								XmlMessage ack1 = new XmlMessage(true);
								ack1.setMID(reqXmlMessage.getMID());
								ack1.setREPTAG(0);
								ack1.setRTT(String.valueOf(receiveTime));
								ack1.setSIG(null);
								ack1.setRC("0");
								ack1.setDS("postHttpReqTimeout");
								ack1.setDATA(serviceInformationRecharge.asXML());
								String respXMLa = convertResponseString(ack1);
								logger.info(respXMLa);
								byte[] resps = respXMLa.getBytes("UTF-8");
								ack1.setLength(resps.length);
								ack1.setMsgTime(System.currentTimeMillis());
								body.write(resps);
								body.close();
							}
							
						}
					//RechargeExtractQuery.BestPay翼支付充值不可提现查询
					 else if (reqXmlMessage.getSCID().equals("RechargeExtractQuery.BestPay@027.ctnbc-bon.net")){
							logger.info("======RechargeExtractQuery.BestPay.getDATA()======"
									+ reqXmlMessage.getDATA());
							Map<String, Object> map = xmlStrToMaps(reqXmlMessage
									.getDATA());
							String productNo= (String) map.get("PRODUCTNO");
							String accountType = (String) map.get("ACCOUNTTYPE");
							String businessType = (String) map.get("BUSINESSTYPE");
							String txnType = (String) map.get("TXNTYPE");
							String supplyOrgCode = (String) map.get("SUPPLYORGCODE");
							String acceptOrgCode = (String) map.get("ACCEPTORGCODE");
							String acceptChannel = (String) map.get("ACCEPTCHANNEL");
							String inputTime = (String) map.get("INPUTTIME");
							String chargeSeqNo = (String) map.get("CHARGESEQNO");
							String maxRecord = (String) map.get("MAXRECORD");
							String startRecord = (String) map.get("STARTRECORD");
							String acceptDate = (String) map.get("ACCEPTDATE");
							String txnAmount = (String) map.get("TXNAMOUNT");
							
							int a=(int)((Math.random()*9+1)*100000);
							long currentTime = System.currentTimeMillis();
							SimpleDateFormat formatter = new SimpleDateFormat("yyyymmddHH");
							Date date = new Date(currentTime);
							String time	=formatter.format(date);
							logger.info("======time======"+ time);
							
							StringBuffer para = new StringBuffer();
							para.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
							para.append("xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ");
							para.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
							para.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");
							para.append("<SOAP-ENV:Body> ");
							para.append("<m:dispatchCommand xmlns:m=\"http://control.ppcore.haobai.huateng.com\"> ");
							para.append("<m:in0>");
							para.append("100102|420000-TEST1-127.0.0.1|127.0.0.1|1.0");
							para.append("</m:in0> ");
							para.append("<m:in1> ");
							
							para.append("<![CDATA[");
							para.append("<PayPlatRequestParameter> ");
							para.append("<CTRL-INFO WEBSVRNAME=\"SGW\" WEBSVRCODE=\"100102\" APPFROM=\"420000-SGW-127.0.0.1\" KEEP=\""+time+String.valueOf(a)+"\"/> ");
							para.append("<PARAMETERS>");
							para.append("<PRODUCTNO>" + productNo + "</PRODUCTNO>");
							para.append("<ACCOUNTTYPE>" + accountType + "</ACCOUNTTYPE>");
							para.append("<BUSINESSTYPE>" + businessType + "</BUSINESSTYPE>");
							para.append("<ACCEPTCHANNEL>" + acceptChannel + "</ACCEPTCHANNEL>");
							para.append("<TXNTYPE>" + txnType + "</TXNTYPE>");
							para.append("<SUPPLYORGCODE>" + supplyOrgCode + "</SUPPLYORGCODE>");
							para.append("<ACCEPTORGCODE>" + acceptOrgCode + "</ACCEPTORGCODE>");
							para.append("<CHARGESEQNO>" + chargeSeqNo + "</CHARGESEQNO>");
							para.append("<TXNAMOUNT>" + txnAmount + "</TXNAMOUNT>");
							para.append("<MAXRECORD>" + maxRecord + "</MAXRECORD>");
							para.append("<STARTRECORD>" + startRecord + "</STARTRECORD>");
//							para.append("<INPUTTIME>" + inputTime + "</INPUTTIME>");
							para.append("</PARAMETERS>");
							para.append("</PayPlatRequestParameter>");
							para.append("]]> ");
							
							
							para.append("</m:in1> ");
							para.append("</m:dispatchCommand> ");
							para.append("</SOAP-ENV:Body> ");
							para.append("</SOAP-ENV:Envelope> ");
							
							boolean sendOK = false;
							logger.info("===============para.toString()============" + para.toString());
							String url  = RechargeExtractQueryURL;
							logger.info("===============调用地址url============" + url);
							PostMethod post = new PostMethod(url);
							String resp = "";
							RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
							post.setRequestEntity(requestEntity);
							HttpClient client = new HttpClient();
//							int timeout = configService.getIntValue(SysParamBean.KEY_AGREEMENT_SCSP_MSG_Timeout, 60);
							client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
							client.executeMethod(post);
							resp = post.getResponseBodyAsString();
							logger.info("==============resp========" + resp);
							String respss=resp.replaceAll("&lt;", "<").replaceAll("&#xd;", "");
							String code=respss.split("<RESPONSECODE>")[1].split("</RESPONSECODE>")[0];
							logger.info("==============code========" + code);
							if(code.equals("000000")){
								String dates="<Result>0</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
								
								XmlMessage ack = new XmlMessage(true);
								ack.setMID(reqXmlMessage.getMID());
								ack.setREPTAG(0);
								ack.setRTT(String.valueOf(receiveTime));
								ack.setSIG(null);
								ack.setRC("0");
								ack.setDS("SUCCESS");
								ack.setDATA(dates);
								String respXML = convertResponseString(ack);
								logger.info("=======================respXML========================");
								logger.info(respXML);
								logger.info("=======================respXML========================");
								byte[] resps = respXML.getBytes("UTF-8");
								ack.setLength(resps.length);
								ack.setMsgTime(System.currentTimeMillis());
								body.write(resps);
								body.close();
							}else{
								String dates="<Result>1</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
								
								XmlMessage ack = new XmlMessage(true);
								ack.setMID(reqXmlMessage.getMID());
								ack.setREPTAG(0);
								ack.setRTT(String.valueOf(receiveTime));
								ack.setSIG(null);
								ack.setRC("0");
								ack.setDS("SUCCESS");
								ack.setDATA(dates);
								String respXML = convertResponseString(ack);
								logger.info("=======================respXML========================");
								logger.info(respXML);
								logger.info("=======================respXML========================");
								byte[] resps = respXML.getBytes("UTF-8");
								ack.setLength(resps.length);
								ack.setMsgTime(System.currentTimeMillis());
								body.write(resps);
								body.close();
							}
							
						}
					//RechargeExtractRollback.BestPay翼支付充值不可提现撤销
					 else if (reqXmlMessage.getSCID().equals(
								"RechargeExtractRollback.BestPay@027.ctnbc-bon.net")) {
							logger.info("======RechargeExtractRollback.BestPay.getDATA()======"
									+ reqXmlMessage.getDATA());
							Map<String, Object> map = xmlStrToMaps(reqXmlMessage
									.getDATA());
							String productNo= (String) map.get("PRODUCTNO");
							String accountType = (String) map.get("ACCOUNTTYPE");
							String businessType = (String) map.get("BUSINESSTYPE");
							String txnType = (String) map.get("TXNTYPE");
							String txnAmount = (String) map.get("TXNAMOUNT");
							String feeFlag = (String) map.get("FEEFLAG");
							String feeAmt = (String) map.get("FEEAMT");
							String supplyOrgCode = (String) map.get("SUPPLYORGCODE");
							String acceptOrgCode = (String) map.get("ACCEPTORGCODE");
							
							String acceptUid = "";
							if(map.get("ACCEPTUID")!=null&&!"".equals(map.get("ACCEPTUID"))){
								acceptUid=map.get("ACCEPTUID").toString();
							}
							
							String acceptAreaCode = (String) map.get("ACCEPTAREACODE");
							String acceptCityCode = (String) map.get("ACCEPTCITYCODE");
							String acceptChannel = (String) map.get("ACCEPTCHANNEL");
							String acceptSeqNo = (String) map.get("ACCEPTSEQNO");
							String acceptTransDate = (String) map.get("ACCEPTTRANSDATE");
							String acceptTransTime = (String) map.get("ACCEPTTRANSTIME");
							String oldAcceptSeqNo = (String) map.get("OLDACCEPTSEQNO");
							String oldAcceptTransDate = (String) map.get("OLDACCEPTTRANSDATE");
							String oldAcceptTransTime = (String) map.get("OLDACCEPTTRANSTIME");
							String inputTime = (String) map.get("INPUTTIME");
							String areaCode = (String) map.get("Area_Code");
							String staffId = (String) map.get("Staff_Id");
							String channelId = (String) map.get("Channel_Id");
							String siteId = (String) map.get("Site_Id");
							String operType = (String) map.get("Oper_Type");
							
							int a=(int)((Math.random()*9+1)*100000);
							long currentTime = System.currentTimeMillis();
							SimpleDateFormat formatter = new SimpleDateFormat("yyyymmddHH");
							Date date = new Date(currentTime);
							String time	=formatter.format(date);
							logger.info("======time======"+ time);
							
							
							StringBuffer para = new StringBuffer();
							
							para.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
							para.append("xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ");
							para.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
							para.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");
							para.append("<SOAP-ENV:Body> ");
							para.append("<m:dispatchCommand xmlns:m=\"http://control.ppcore.haobai.huateng.com\"> ");
							para.append("<m:in0>");
							para.append("200402|420000-TEST1-127.0.0.1|127.0.0.1|1.0");
							para.append("</m:in0> ");
							para.append("<m:in1> ");
							
							para.append("<![CDATA[");
							para.append("<PayPlatRequestParameter> ");
							para.append("<CTRL-INFO WEBSVRNAME=\"SGW\" WEBSVRCODE=\"200402\" APPFROM=\"420000-SGW-127.0.0.1\" KEEP=\""+time+String.valueOf(a)+"\"/> ");
							para.append("<PARAMETERS>");
							para.append("<PRODUCTNO>" + productNo + "</PRODUCTNO>");
							para.append("<ACCOUNTTYPE>" + accountType + "</ACCOUNTTYPE>");
							para.append("<BUSINESSTYPE>" + businessType + "</BUSINESSTYPE>");
							para.append("<TXNTYPE>" + txnType + "</TXNTYPE>");
							para.append("<TXNAMOUNT>" + txnAmount + "</TXNAMOUNT>");
							para.append("<FEEFLAG>" + feeFlag + "</FEEFLAG>");
							para.append("<FEEAMT>" + feeAmt + "</FEEAMT>");
							
							
							para.append("<SUPPLYORGCODE>" + supplyOrgCode + "</SUPPLYORGCODE>");
//							para.append("<TERMINALSEQNO>" + terminalSeqNo + "</TERMINALSEQNO>");
							para.append("<ACCEPTORGCODE>" + acceptOrgCode + "</ACCEPTORGCODE>");
							para.append("<ACCEPTUID>" + acceptUid + "</ACCEPTUID>");
							
							para.append("<ACCEPTAREACODE>" + acceptAreaCode + "</ACCEPTAREACODE>");
							para.append("<ACCEPTCITYCODE>" + acceptCityCode + "</ACCEPTCITYCODE>");
							para.append("<ACCEPTCHANNEL>" + acceptChannel + "</ACCEPTCHANNEL>");
							para.append("<ACCEPTSEQNO>" + acceptSeqNo + "</ACCEPTSEQNO>");
							para.append("<ACCEPTTRANSDATE>" + acceptTransDate + "</ACCEPTTRANSDATE>");
							para.append("<ACCEPTTRANSTIME>" + acceptTransTime + "</ACCEPTTRANSTIME>");
							
							para.append("<OLDACCEPTSEQNO>" + oldAcceptSeqNo + "</OLDACCEPTSEQNO>");
							para.append("<OLDACCEPTTRANSDATE>" + oldAcceptTransDate + "</OLDACCEPTTRANSDATE>");
							para.append("<OLDACCEPTTRANSTIME>" + oldAcceptTransTime + "</OLDACCEPTTRANSTIME>");
//							para.append("<CHECKUID>" + checkuid + "</CHECKUID>");
							
							
							para.append("<INPUTTIME>" + inputTime + "</INPUTTIME>");
							para.append("</PARAMETERS>");
							para.append("</PayPlatRequestParameter>");
							para.append("]]> ");
							
							
							para.append("</m:in1> ");
							para.append("</m:dispatchCommand> ");
							para.append("</SOAP-ENV:Body> ");
							para.append("</SOAP-ENV:Envelope> ");
							
							boolean sendOK = false;
							logger.info("===============para.toString()============" + para.toString());
							String url  = RechargeExtractURL;
							logger.info("===============调用地址url============" + url);
							PostMethod post = new PostMethod(url);
							String resp = "";
							RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
							post.setRequestEntity(requestEntity);
							HttpClient client = new HttpClient();
//							int timeout = configService.getIntValue(SysParamBean.KEY_AGREEMENT_SCSP_MSG_Timeout, 60);
							client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
							client.executeMethod(post);
							resp = post.getResponseBodyAsString();
						
							logger.info("==============resp========" + resp);
							
							String respss=resp.replaceAll("&lt;", "<").replaceAll("&#xd;", "");
							String code=respss.split("<RESPONSECODE>")[1].split("</RESPONSECODE>")[0];
							
							if(code.equals("000000")){
								String dates="<Result>0</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
								
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
								
								
								
								Element serviceInformation = DocumentHelper.createElement("Service_Information");
								Element element = serviceInformation.addElement("Area_Code");
								element.setText(areaCode);
								element = serviceInformation.addElement("Acc_Nbr");
								element.setText(productNo);
								element = serviceInformation.addElement("Block_Date");
								element.setText(acceptTransDate);
								element = serviceInformation.addElement("Staff_Id");
								element.setText(staffId);
								element = serviceInformation.addElement("Balance_Amount");
								element.setText((Long.valueOf(txnAmount)*-1)+"");
								element = serviceInformation.addElement("Reverse_Amount");
								element.setText("0");
								element = serviceInformation.addElement("Channel_Id");
								element.setText(channelId);
								element = serviceInformation.addElement("Site_Id");
								element.setText(siteId);
								element = serviceInformation.addElement("Oper_Type");
								element.setText(operType);
								element = serviceInformation.addElement("Oper_Serial_Nbr");
								element.setText(acceptSeqNo);
								element = serviceInformation.addElement("Oper_serial");
								element.setText(oldAcceptSeqNo);
								WingBalanceQuery wingBalanceQuery = new WingBalanceQuery("", "", "", "", "", "", "");
								XmlMessage req = new XmlMessage(true);
								req.setIp(IP);
								req.setMsgTime(receiveTime);
								req.setMID(reqXmlMessage.getMID());
								req.setUID(reqXmlMessage.getUID());
								if(areaCode.equals("027")){
									req.setSCID("JfzsRechargeInfoSave.WH@027.ctnbc-bon.net");
								}else{
									req.setSCID("JfzsRechargeInfoSave.HB@027.ctnbc-bon.net");
								}
								req.setSIG(null);
								req.setREPTAG(0);
								req.setDATA(serviceInformation.asXML());
								req.setDataElement(serviceInformation);
								// new CallParam对象
								RechargeExtractHandle rechargeHandle = new RechargeExtractHandle(body,map,reqXmlMessage,IP,"","",wingBalanceQuery,tyConfigService.getValue("APP_CODE", ""),tyConfigService.getValue("IP", ""),tyConfigService.getValue("VERSION", ""),dates);
								CallParam callParam = new CallParam(req.getMID(), req.getSCID(),req, req.getUID(), rechargeHandle);
								BuzProcessorManager.getInstance().processRequest(callParam);
								
							}else{
								String dates="<Result>1</Result><RESPONSECODE>"+respss.split("<RESPONSECODE>")[1].split("</PayPlatResponseParameter>")[0];
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(1);
								bean.setResultCode(Integer.valueOf(respss.split("<RESPONSECODE>")[1].split("</RESPONSECODE>")[0]));
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
								
								XmlMessage ack = new XmlMessage(true);
								ack.setMID(reqXmlMessage.getMID());
								ack.setREPTAG(0);
								ack.setRTT(String.valueOf(receiveTime));
								ack.setSIG(null);
								ack.setRC("0");
								ack.setDS("SUCCESS");
								ack.setDATA(dates);
								String respXML = convertResponseString(ack);
								logger.info("=======================respXML========================");
								logger.info(respXML);
								logger.info("=======================respXML========================");
								byte[] resps = respXML.getBytes("UTF-8");
								ack.setLength(resps.length);
								ack.setMsgTime(System.currentTimeMillis());
								body.write(resps);
								body.close();
								
							}
							
						}
					// 多账期宽带续费CyclesRenew.ADSL
					else if (reqXmlMessage.getSCID().equals(
							"CyclesRenew.ADSL@027.ctnbc-bon.net")) {
						logger.info("======CyclesRenew.ADSL.getDATA()======"
								+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage
								.getDATA());
						String areaCode = (String) map.get("Area_Code");
						String balanceTypeID = (String) map
								.get("balanceTypeID");
						String custPricePlanID = (String) map
								.get("custPricePlanID");
						String cyclesCharge = (String) map.get("cyclesCharge");
						String cyclesMonth = (String) map.get("cyclesMonth");
						String cyclesFlag = (String) map.get("cyclesFlag");
						String destinationId = (String) map
								.get("destinationId");
						String delayType = (String) map.get("delayType");
						String expDate = (String) map.get("expDate");
						String requestId = (String) map.get("requestId");
						String requestTime = (String) map.get("requestTime");
						String servId = (String) map.get("servId");
						String staffId = (String) map.get("staffId");

						String url = null;
						if (areaCode.equals("027")) {
							url = AdslCycleUrlWH;
						} else {
							url = AdslCycleUrlHB;
						}
						logger.info("===============调用地址url============" + url);
						UvcSoapForOcsServiceProxy proxy = new UvcSoapForOcsServiceProxy(
								url);
						CyclesRenewRequest cqr = new CyclesRenewRequest();
						cqr.setBalanceTypeId(Long.parseLong(balanceTypeID));
						cqr.setCustPricePlanId(custPricePlanID);
						cqr.setCyclesCharge(Integer.parseInt(cyclesCharge));
						cqr.setCyclesMonth(Long.parseLong(cyclesMonth));
						cqr.setCyclesFlag(Integer.parseInt(cyclesFlag));
						cqr.setDestinationId(destinationId);
						cqr.setDelayType(delayType);
						cqr.setExpDate(expDate);
						cqr.setRequestId(requestId);
						cqr.setRequestTime(requestTime);
						cqr.setServId(servId);
						cqr.setStaffId(Integer.parseInt(staffId));
						CyclesRenewResponse resp = proxy.cyclesRenew(cqr);

						String renewSerialNbr = resp.getRenewSerialNbr();
						String responseId = resp.getResponseId();
						String responseTime = resp.getResponseTime();
						int returnCode = resp.getReturnCode();

						Element serviceInformation = DocumentHelper
								.createElement("Service_Information");
						Element element = serviceInformation
								.addElement("Result");
						if (returnCode == 0) {
							element.setText(String.valueOf(returnCode));
							element = serviceInformation
									.addElement("renewSerialNbr");
							if (renewSerialNbr == null
									|| renewSerialNbr.equals("")) {
								element.setText("");
							} else {
								element.setText(renewSerialNbr);
							}
							element = serviceInformation
									.addElement("responseId");
							if (responseId == null || responseId.equals("")) {
								element.setText("");
							} else {
								element.setText(responseId);
							}
							element = serviceInformation
									.addElement("responseTime");
							if (responseTime == null
									|| responseTime.equals("")) {
								element.setText("");
							} else {
								element.setText(responseTime);
							}
							element = serviceInformation
									.addElement("returnCode");
							element.setText(String.valueOf(returnCode));
						} else {
							element.setText(String.valueOf(returnCode));
							element = serviceInformation
									.addElement("renewSerialNbr");
							if (renewSerialNbr == null
									|| renewSerialNbr.equals("")) {
								element.setText("");
							} else {
								element.setText(renewSerialNbr);
							}
						}
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(returnCode);
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
						
						tmallLogDao.insertBusinessRecordPort(bean);
						
						XmlMessage ack = new XmlMessage(true);
						ack.setMID(reqXmlMessage.getMID());
						ack.setREPTAG(0);
						ack.setRTT(String.valueOf(receiveTime));
						ack.setSIG(null);
						ack.setRC("0");
						ack.setDS("SUCCESS");
						ack.setDATA(serviceInformation.asXML());
						String respXML = convertResponseString(ack);
						logger.info("=======================respXML========================");
						logger.info(respXML);
						logger.info("=======================respXML========================");
						byte[] resps = respXML.getBytes("UTF-8");
						ack.setLength(resps.length);
						ack.setMsgTime(System.currentTimeMillis());
						body.write(resps);
						body.close();

					}
					/////////////////////////高额接口查询HighCostHquery.HBXD/////////////////////////////////////////
					 else if (reqXmlMessage.getSCID().equals(
								"HighCostHquery.HBXD@027.ctnbc-bon.net")) {
							logger.info("======HighCostHquery.HBXD.getDATA()======"
									+ reqXmlMessage.getDATA());
							Map<String, Object> map = xmlStrToMaps(reqXmlMessage
									.getDATA());
							String type = (String) map.get("type");
							String from  = (String) map.get("from");
							String acctNbr  = (String) map.get("acctNbr");
							String acctDay  = (String) map.get("acctDay");

							StringBuffer para = new StringBuffer();
							para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.hquery.ailk.com/\">");
							para.append("<soapenv:Header/>");
							para.append("<soapenv:Body>");
							para.append("<ws:HighCostHquery>");
							para.append("<param><![CDATA[  ");
							para.append("<query type='" + type + "' from='" + from + "'>");
							para.append("<param name='acctNbr'>" + acctNbr + "</param>");
							para.append("<param name='acctDay'>" + acctDay + "</param>");
							para.append("</query>");
							para.append("]]>");
							para.append("</param>");
							para.append("</ws:HighCostHquery>");
							para.append("</soapenv:Body>");
							para.append("</soapenv:Envelope>");
							boolean sendOK = false;
							logger.info("===============para.toString()============" + para.toString());
							String url  = HighCostHquery;
							logger.info("===============调用地址url============" + url);
							PostMethod post = new PostMethod(url);
							String resp = "";
							int retCode = 0;
							String data = "";
							try {
								RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
								post.setRequestEntity(requestEntity);
								HttpClient client = new HttpClient();
//								int timeout = configService.getIntValue(SysParamBean.KEY_AGREEMENT_SCSP_MSG_Timeout, 60);
								client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
								client.getHttpConnectionManager().getParams().setSoTimeout(20 * 1000);
								client.executeMethod(post);
								resp = post.getResponseBodyAsString();
								logger.info("==============resp========" + resp);
								//解析返回串
								sendOK = true;
								if(resp.length() == 0 ) {
									 StringBuffer stringBuffer = new StringBuffer();
									 stringBuffer.append("<Service_Information>");
									 stringBuffer.append("<retCode>");
									 stringBuffer.append(TIMEOUT);
									 stringBuffer.append("</retCode>");
									 stringBuffer.append("<errMsg>");
									 stringBuffer.append("请求超时");
									 stringBuffer.append("</errMsg>");
									 stringBuffer.append("</Service_Information>");
									 retCode = TIMEOUT;
									 data = stringBuffer.toString();
								} else {
									if(sendOK){
										try {
											data = parseNetListReturn(resp);
											retCode = 0;
											logger.info("==============data========" + data);
										} catch (Exception e) {
											logger.warn("response  is valid.", e);
										}
									}
									
								}
							} catch (Exception e) {
								 StringBuffer stringBuffer = new StringBuffer();
								 stringBuffer.append("<Service_Information>");
								 stringBuffer.append("<retCode>");
								 stringBuffer.append(TIMEOUT);
								 stringBuffer.append("</retCode>");
								 stringBuffer.append("<errMsg>");
								 stringBuffer.append("请求超时");
								 stringBuffer.append("</errMsg>");
								 stringBuffer.append("</Service_Information>");
								 retCode = TIMEOUT;
								 data = stringBuffer.toString();
							}
							BusinessRecordPort bean= new BusinessRecordPort();
							bean.setSessionId(reqXmlMessage.getMID());
							bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
									.currentTimeMillis()));
							bean.setRequestHost(reqXmlMessage.getUID());
							bean.setServiceContextId(reqXmlMessage.getSCID());
							bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
									.currentTimeMillis()));
							bean.setResult(retCode);
							TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
							tmallLogDao.insertBusinessRecordPort(bean);
							XmlMessage ack = new XmlMessage(true);
							ack.setMID(reqXmlMessage.getMID());
							ack.setREPTAG(0);
							ack.setRTT(String.valueOf(receiveTime));
							ack.setSIG(null);
							ack.setRC(String.valueOf(retCode));
							if(retCode != 0) {
								ack.setDS("BON TimeOut");
							}
							ack.setDATA(data);
							String respXML = convertResponseString(ack);
							logger.info("=======================respXML========================");
							logger.info(respXML);
							logger.info("=======================respXML========================");
							byte[] resps = respXML.getBytes("UTF-8");
							ack.setLength(resps.length);
							ack.setMsgTime(System.currentTimeMillis());
							body.write(resps);
							body.close();

						}
					//////////////////////////////////////////////////////////////////
					////////////////////////综合查询QueryChargeScene.HB//////////////////////////////////////////
					
					 else if (reqXmlMessage.getSCID().equals("QueryChargeScene.HB@027.ctnbc-bon.net")) {
							logger.info("======QueryChargeScene.HB.getDATA()======"+ reqXmlMessage.getDATA());
							Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
							String regionId = (String) map.get("REGION_ID");
							logger.info("==============regionId========" + regionId);
							String accNbr = (String) map.get("ACC_NBR");
							logger.info("==============accNbr========" + accNbr);
							String areaCode = (String) map.get("AREA_CODE");
							logger.info("==============areaCode========" + areaCode);

							String url = null;
							if (areaCode.equals("027")) {
								url = QueryChargeSceneWH;
							} else {
								url = QueryChargeSceneHB;
							}
							logger.info("===============调用地址url============" + url);
							BossServicePortTypeProxy proxy = new BossServicePortTypeProxy(
									url);
							
							QueryChargeSceneRequest qcsr = new QueryChargeSceneRequest();
							qcsr.setACC_NBR(accNbr);
							qcsr.setAREA_CODE(areaCode);
							qcsr.setREGION_ID(regionId);
							QueryChargeSceneResponse resp = proxy.queryChargeScene(qcsr);
						
							
							
							int result = resp.getRESULT();
							logger.info("==============result========" + result);
							String errMsg = resp.getERR_MSG();
							logger.info("==============errMsg========" + errMsg);
							String feeType =String.valueOf(resp.getFEE_TYPE());
							logger.info("==============feeType========" + feeType);
							String feeInfo = resp.getFEE_INFO();
							logger.info("==============feeInfo========" + feeInfo);

							Element serviceInformation = DocumentHelper.createElement("Service_Information");
							Element element = serviceInformation.addElement("Result");
							element.setText(String.valueOf(result));
							element = serviceInformation.addElement("RESULT");
							element.setText(String.valueOf(result));
							
							element = serviceInformation.addElement("ERR_MSG");
							if (errMsg == null|| errMsg.equals("")) {
									element.setText("");
								} else {
									element.setText(errMsg);
								}
							
							element = serviceInformation.addElement("FEE_TYPE");
							if (feeType == null|| feeType.equals("")) {
									element.setText("");
								} else {
									element.setText(feeType);
								}
							
							element = serviceInformation.addElement("FEE_INFO");
							if (feeInfo == null|| feeInfo.equals("")) {
									element.setText("");
								} else {
									element.setText(feeInfo);
								}
							
							
							BusinessRecordPort bean= new BusinessRecordPort();
							bean.setSessionId(reqXmlMessage.getMID());
							bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
									.currentTimeMillis()));
							bean.setRequestHost(reqXmlMessage.getUID());
							bean.setServiceContextId(reqXmlMessage.getSCID());
							bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
									.currentTimeMillis()));
							bean.setResult(result);
							TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
							
							tmallLogDao.insertBusinessRecordPort(bean);
							
							XmlMessage ack = new XmlMessage(true);
							ack.setMID(reqXmlMessage.getMID());
							ack.setREPTAG(0);
							ack.setRTT(String.valueOf(receiveTime));
							ack.setSIG(null);
							ack.setRC("0");
							ack.setDS("SUCCESS");
							ack.setDATA(serviceInformation.asXML());
							String respXML = convertResponseString(ack);
							logger.info("=======================respXML========================");
							logger.info(respXML);
							logger.info("=======================respXML========================");
							byte[] resps = respXML.getBytes("UTF-8");
							ack.setLength(resps.length);
							ack.setMsgTime(System.currentTimeMillis());
							body.write(resps);
							body.close();

						}
					
////////////////////////拆机用户缴费OutBlockUp.HB//////////////////////////////////////////					
				 else if (reqXmlMessage.getSCID().equals("OutBlockUp.HB@027.ctnbc-bon.net")) {
					 logger.info("======OutBlockUp.HB.getDATA()======"+ reqXmlMessage.getDATA());
					 Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					 String regionId = (String) map.get("regionId");
					 String accNbr = (String) map.get("accNbr");
					 String blockState = (String) map.get("blockState");
					 String staffId = (String) map.get("staffId");

                    String jf3_flag = userResourceConfigService.getValue("jf3_flag", "");
                    String jf3_latn_id = userResourceConfigService.getValue("jf3_latn_id", "");


                    logger.info("=========OutBlockUp.HB========blockState:"+blockState);
                        logger.info("=========OutBlockUp.HB========jf3_flag:"+jf3_flag);
                        logger.info("=========OutBlockUp.HB========jf3_latn_id:"+jf3_latn_id);
                        logger.info("=========OutBlockUp.HB========regionId:"+regionId);
                        if(("141".equals(blockState) || "142".equals(blockState))
                            &&  !"0".equals(jf3_flag)
                            &&  ("888".equals(jf3_latn_id) || jf3_latn_id.contains(regionId)) ){
                        //满足以上三个条件则走3.0新的DCC接口，否则都走老接口。
                            logger.info("=========OutBlockUp.HB========计费3.0=======");
                            map.put("receiveTime",receiveTime);
                        Element serviceInformation = DocumentHelper.createElement("Service_Information");
                        serviceInformation.addElement("Channel_Id").setText("200");
                        serviceInformation.addElement("Area_Code").setText(StringUtil.getRegionId(regionId));
                        serviceInformation.addElement("Latn_Id").setText(regionId);
                        serviceInformation.addElement("DestinationAttr").setText("99");
                        serviceInformation.addElement("Destination_Id").setText(StringUtil.getRegionId(regionId)+accNbr);
                        serviceInformation.addElement("Destination_Id_Type").setText("2");
                        serviceInformation.addElement("ValueType").setText("1");
                        serviceInformation.addElement("Value").setText("0");
                        serviceInformation.addElement("Return_Time").setText("0");

                        XmlMessage req = new XmlMessage(true);
//                        String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
//                        String sessionId = DiameterUtils.makeSessionID(tmallHostId);
                        req.setIp(IP);
                        req.setMsgTime(receiveTime);
//                        req.setMID(sessionId);
//                        req.setUID(tmallHostId);
                            req.setMID(reqXmlMessage.getMID());
                            req.setUID(reqXmlMessage.getUID());
                        req.setSCID("EmergencyBoot.jf3@027.ctnbc-bon.net");
                        req.setSIG(null);
                        req.setREPTAG(0);
                        req.setDATA(serviceInformation.asXML());
                            //记录到BUSNIESS_RECORD_PORT表
                            LogBusniessRecordPort(reqXmlMessage, 0, null);
                        // new CallParam对象
                        OutBlockUpHandle accuUseDetailQryHandle = new OutBlockUpHandle(body,map,reqXmlMessage);
                        CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), accuUseDetailQryHandle);
                        BuzProcessorManager.getInstance().processRequest(callParam);
//                            writeOutResponseMessage(receiveTime, body, reqXmlMessage, stringBuffer);

                            return;
                    }else {
                        //得到发送webservice请求的信息
                        StringBuffer para = getSendWebServiceInfo(regionId, accNbr,blockState, staffId);
                        String url = regionId.equals(IS_WD) ? OutBlockUpWH : OutBlockUpHB;
                        logger.info("===============发到下游的消息============" + para.toString());
                        logger.info("===============调用地址url============" + url);
                        PostMethod post = new PostMethod(url);
                        post.setRequestHeader("SOAPAction", "");
                        String resp = "";
                        //得到下游返回的信息
                        StringBuffer resBuffer = getResponseMessage(para, post);
                        resp = resBuffer.toString();
                        String data = "";
                        int retCode = 0;
                        String errMes = "";
                        boolean sendOK = true;
                        StringBuffer stringBuffer = null;
                        if(resBuffer.length() == 0 ) {
                            stringBuffer = new StringBuffer();
                            stringBuffer.append("<Service_Information>");
                            stringBuffer.append("<retCode>");
                            stringBuffer.append(TIMEOUT);
                            stringBuffer.append("</retCode>");
                            stringBuffer.append("<errMsg>");
                            stringBuffer.append("请求超时");
                            stringBuffer.append("</errMsg>");
                            stringBuffer.append("</Service_Information>");
                            retCode = TIMEOUT;
                            errMes = "请求超时";
                        } else {
                            if(sendOK){
                                try {
                                    logger.info("----66666666----");
                                    data = parseNetListReturnObur(resp);
                                    logger.info("data" +data);
                                    Document doc = DocumentHelper.parseText(data);
                                    List<org.dom4j.Node> nodes=doc.selectNodes("//OutBlockUpResponse");
                                    logger.info("nodes" +nodes.size());
                                    Element e1=(Element)nodes.get(0);
                                    logger.info("retCode" +e1.element("retCode").getText());
                                    for (org.dom4j.Node node : nodes) {
                                        Element e=(Element)node;
                                        Element retCodeElement=e.element("retCode");
                                        Element errMesElement=e.element("errMsg");
                                        retCode = Integer.parseInt(retCodeElement.getText());
                                        errMes = errMesElement.getText();
                                    }
                                    stringBuffer = new StringBuffer();
                                    stringBuffer.append("<Service_Information>");
                                    stringBuffer.append("<retCode>");
                                    stringBuffer.append(retCode);
                                    stringBuffer.append("</retCode>");
                                    stringBuffer.append("<errMsg>");
                                    stringBuffer.append(errMes);
                                    stringBuffer.append("</errMsg>");
                                    stringBuffer.append("</Service_Information>");

                                } catch (Exception e) {
                                    logger.warn("response  is valid.", e);
                                }
                            }
                        }
                        //记录到BUSNIESS_RECORD_PORT表
                        LogBusniessRecordPort(reqXmlMessage, retCode, errMes);
                        logger.info("下游响应的消息"+resp);
                        //输出下游返回的信息
                        writeOutResponseMessage(receiveTime, body, reqXmlMessage, stringBuffer);
                    }

				 }
				 //流量回溯查询接口QueryFluxCover.HB///////
				 else if (reqXmlMessage.getSCID().equals("QueryFluxCover.HB@027.ctnbc-bon.net")) {
					 logger.info("======QueryFluxCover.HB.getDATA()======"+ reqXmlMessage.getDATA());
					 Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					 String regionId = (String) map.get("REGION_ID");
					 String accNbr = (String) map.get("ACC_NBR");
					 StringBuffer para = getQueryFluxCoverSendWebServiceInfo(regionId, accNbr);
					 String url = regionId.equals(IS_WD) ? QueryFluxCoverWH : QueryFluxCoverHB;
					 int retCode = 0;
					 String errMes = "";
					 logger.info("===============发到下游的消息============" + para.toString());
					 logger.info("===============调用地址url============" + url);
					 PostMethod post = new PostMethod(url);
					 post.setRequestHeader("SOAPAction", "");
					 String resp = "";
					 //得到下游返回的信息
					 RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
					 post.setRequestEntity(requestEntity);
					 HttpClient client = new HttpClient();
					 StringBuffer resBuffer = new StringBuffer(); 
					 StringBuffer stringBuffer = null;
					 client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
					 try {
						 client.executeMethod(post);
						 InputStream resStream = post.getResponseBodyAsStream();
						 BufferedReader br = new BufferedReader(new InputStreamReader(resStream));
						 String resTemp = "";
						 while((resTemp = br.readLine()) != null){  
						    resBuffer.append(resTemp);  
						 }
						 logger.info("resBuffer666666" + resBuffer.length());
						 resp = resBuffer.toString();
						 String data = "";
						 String dataWriteOut = "";
						 boolean sendOK = true;
						 logger.info("resBuffer" + resBuffer.length());
						 if(resBuffer.length() == 0 ) {
							 stringBuffer = new StringBuffer();
							 stringBuffer.append("<Service_Information>");
							 stringBuffer.append("<retCode>");
							 stringBuffer.append(TIMEOUT);
							 stringBuffer.append("</retCode>");
							 stringBuffer.append("<errMsg>");
							 stringBuffer.append("请求超时");
							 stringBuffer.append("</errMsg>");
							 stringBuffer.append("</Service_Information>");
							 retCode = TIMEOUT;
							 errMes = "请求超时";
						 } else {
							if(sendOK){
								try {
									 logger.info("----66666666----");
									 Map<String, String> dataMap = parseQueryFluxCoverNetListReturnObur(resp);
									 for(Map.Entry<String, String> entry : dataMap.entrySet()) {
										 data = entry.getKey();
										 dataWriteOut = entry.getValue();
									 }
									 Document doc = DocumentHelper.parseText(data);
									 List<org.dom4j.Node> nodes=doc.selectNodes("//QueryFluxCoverResponse");
									 logger.info("nodes" +nodes.size());
									 Element e1=(Element)nodes.get(0);
									 logger.info("RESULT" +e1.element("RESULT").getText());
									 for (org.dom4j.Node node : nodes) {
										Element e=(Element)node;
										Element retCodeElement=e.element("RESULT");
										Element errMesElement=e.element("RESULT_INFO");
										retCode = Integer.parseInt(retCodeElement.getText());
										errMes = errMesElement.getText();
									 }
									 logger.info("data" +dataWriteOut);
									 stringBuffer = new StringBuffer();
									 stringBuffer.append("<Service_Information>");
									 stringBuffer.append(dataWriteOut);
									 stringBuffer.append("</Service_Information>");
								} catch (Exception e) {
									logger.warn("response  is valid.", e);
								}
							}
						}
					 } catch (Exception e) {
						 errMes = e.getMessage();
						 retCode = 11009;
						 stringBuffer = new StringBuffer();
						 stringBuffer.append("<Service_Information>");
						 stringBuffer.append("<retCode>");
						 stringBuffer.append(11009);
						 stringBuffer.append("</retCode>");
						 stringBuffer.append("<errMsg>");
						 stringBuffer.append(e.getMessage());
						 stringBuffer.append("</errMsg>");
						 stringBuffer.append("</Service_Information>");
					 }
					 
					logger.info("retCode" +retCode);
					logger.info("errMes" + errMes);
					//记录到BUSNIESS_RECORD_PORT表
					LogBusniessRecordPort(reqXmlMessage, retCode, errMes);
				    logger.info("下游响应的消息"+resp);
					//输出下游返回的信息
					writeOutResponseMessage(receiveTime, body, reqXmlMessage, stringBuffer);
				 }
					
				 //流量回溯轨迹查询接口QueryFluxReclean.HB///////
				 else if (reqXmlMessage.getSCID().equals("QueryFluxReclean.HB@027.ctnbc-bon.net")) {
					 logger.info("======QueryFluxReclean.HB.getDATA()======"+ reqXmlMessage.getDATA());
					 Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					 String regionId = (String) map.get("REGION_ID");
					 String accNbr = (String) map.get("ACC_NBR");
					 String accMonth = (String) map.get("ACCT_MONTH");
					 StringBuffer para = getQueryFluxRecleanSendWebServiceInfo(regionId, accNbr, accMonth);
					 String url = regionId.equals(IS_WD) ? QueryFluxRecleanWH : QueryFluxRecleanHB;
					 int retCode = 0;
					 String errMes = "";
					 logger.info("===============发到下游的消息============" + para.toString());
					 logger.info("===============调用地址url============" + url);
					 PostMethod post = new PostMethod(url);
					 post.setRequestHeader("SOAPAction", "");
					 String resp = "";
					 //得到下游返回的信息
					 RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
					 post.setRequestEntity(requestEntity);
					 HttpClient client = new HttpClient();
					 StringBuffer resBuffer = new StringBuffer(); 
					 StringBuffer stringBuffer = null;
					 client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
					 try {
						 client.executeMethod(post);
						 InputStream resStream = post.getResponseBodyAsStream();
						 BufferedReader br = new BufferedReader(new InputStreamReader(resStream));
						 String resTemp = "";
						 while((resTemp = br.readLine()) != null){  
						    resBuffer.append(resTemp);  
						 }
						 logger.info("resBuffer666666" + resBuffer.length());
						 resp = resBuffer.toString();
						 String data = "";
						 String dataWriteOut = "";
						 boolean sendOK = true;
						 logger.info("resBuffer" + resBuffer.length());
						 if(resBuffer.length() == 0 ) {
							 stringBuffer = new StringBuffer();
							 stringBuffer.append("<Service_Information>");
							 stringBuffer.append("<retCode>");
							 stringBuffer.append(TIMEOUT);
							 stringBuffer.append("</retCode>");
							 stringBuffer.append("<errMsg>");
							 stringBuffer.append("请求超时");
							 stringBuffer.append("</errMsg>");
							 stringBuffer.append("</Service_Information>");
							 retCode = TIMEOUT;
							 errMes = "请求超时";
						 } else {
							if(sendOK){
								try {
									 logger.info("----66666666----");
									 Map<String, String> dataMap = parseQueryFluxRecleanNetListReturnObur(resp);
									 for(Map.Entry<String, String> entry : dataMap.entrySet()) {
										 data = entry.getKey();
										 dataWriteOut = entry.getValue();
									 }
									 Document doc = DocumentHelper.parseText(data);
									 List<org.dom4j.Node> nodes=doc.selectNodes("//QueryFluxRecleanResponse");
									 logger.info("nodes" +nodes.size());
									 Element e1=(Element)nodes.get(0);
									 logger.info("RESULT" +e1.element("RESULT").getText());
									 for (org.dom4j.Node node : nodes) {
										Element e=(Element)node;
										Element retCodeElement=e.element("RESULT");
										Element errMesElement=e.element("RESULT_INFO");
										retCode = Integer.parseInt(retCodeElement.getText());
										errMes = errMesElement.getText();
									 }
									 logger.info("data" +dataWriteOut);
									 stringBuffer = new StringBuffer();
									 stringBuffer.append("<Service_Information>");
									 stringBuffer.append(dataWriteOut);
									 stringBuffer.append("</Service_Information>");
								} catch (Exception e) {
									logger.warn("response  is valid.", e);
								}
							}
						}
					 } catch (Exception e) {
						 errMes = e.getMessage();
						 retCode = 11009;
						 stringBuffer = new StringBuffer();
						 stringBuffer.append("<Service_Information>");
						 stringBuffer.append("<retCode>");
						 stringBuffer.append(11009);
						 stringBuffer.append("</retCode>");
						 stringBuffer.append("<errMsg>");
						 stringBuffer.append(e.getMessage());
						 stringBuffer.append("</errMsg>");
						 stringBuffer.append("</Service_Information>");
					 }
					 
					logger.info("retCode" +retCode);
					logger.info("errMes" + errMes);
					//记录到BUSNIESS_RECORD_PORT表
					LogBusniessRecordPort(reqXmlMessage, retCode, errMes);
				    logger.info("下游响应的消息"+resp);
					//输出下游返回的信息
					writeOutResponseMessage(receiveTime, body, reqXmlMessage, stringBuffer);
				 }
					//////////////////////////////////////////////////////////////////
////////////////////////拆机用户欠费查询QueryBlackOwe.HB.HB//////////////////////////////////////////
				 else if (reqXmlMessage.getSCID().equals("QueryBlackOwe.HB@027.ctnbc-bon.net")) {
						logger.info("======QueryBlackOwe.HB.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
						String staffId = (String) map.get("STAFF_ID");
						logger.info("==============staffId========" + staffId);
						String certificateType = (String) map.get("CERTIFICATE_TYPE");
						logger.info("==============certificateType========" + certificateType);
						String certificateNo = (String) map.get("CERTIFICATE_NO");
						logger.info("==============certificateNo========" + certificateNo);
						String channelCode = (String) map.get("CHANNEL_CODE");
						logger.info("==============channelCode========" + channelCode);
						String areaCode = (String) map.get("AREA_CODE");
						logger.info("==============areaCode========" + areaCode);

						String url = null;
						 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
						int urlForJf3 = getURLForJf3(areaCode,IS_WH);
						switch (urlForJf3) {
						case 1://新武汉
							url = QueryBlackOweWHjf3;
							break;
						case 2://新湖北
							url = QueryBlackOweHBjf3;
							break;
						case 3://旧武汉
							url = QueryBlackOweWH;
							break;
						case 4://旧湖北
							url = QueryBlackOweHB;
							break;
							
						default:
							break;
						}
						
//						if (areaCode.equals("027")) {
//							url = QueryBlackOweWH;
//						} else {
//							url = QueryBlackOweHB;
//						}
						logger.info("===============调用地址url============" + url);
						int result=-1;
						Element serviceInformation = DocumentHelper.createElement("Service_Information");
						if(urlForJf3 == 1 || urlForJf3 == 2) {
							logger.info("==============进入新接口======urlForJf3:"+urlForJf3 );
							BillingBossServiceImplServiceSoapBindingStub stu  = new BillingBossServiceImplServiceSoapBindingStub(new java.net.URL(url),null);
							com.asiainfo.webservice.QueryBlackOweRequest queryBlackOweRequest=new com.asiainfo.webservice.QueryBlackOweRequest();
							queryBlackOweRequest.setCERTIFICATE_NO(certificateNo);
							queryBlackOweRequest.setCERTIFICATE_TYPE(certificateType);
							queryBlackOweRequest.setCHANNEL_CODE(channelCode);
							queryBlackOweRequest.setREGION_ID(areaCode);
							queryBlackOweRequest.setSTAFF_ID(staffId);
							logger.info("==============before=======" );
							com.asiainfo.webservice.QueryBlackOweResponse resp = stu.queryBlackOwe(queryBlackOweRequest);
							logger.info("==============after========" );
							
							if(resp.getRESULT()==0){
								 result = resp.getRESULT();
								logger.info("==============result========" + result);
								String errInfo = resp.getERR_INFO();
								logger.info("==============errInfo========" + errInfo);
								com.asiainfo.webservice.OweItem[] oweItem = resp.getOWE_ITEM();
								logger.info("==============oi.length========" + oweItem.length);
							
								Element element = serviceInformation.addElement("Result");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								
								element = serviceInformation.addElement("ERR_INFO");
								if (errInfo == null|| errInfo.equals("	")) {
										element.setText("	");
									} else {
										element.setText(errInfo);
									}
								
								for (int i = 0; i < oweItem.length; i++) {
									logger.info("=============进入for========"+i );
									OWE_ITEM = DocumentHelper.createElement("OWE_ITEM");
									
									
									Element oweItemE= OWE_ITEM.addElement("CERTIFICATE_TYPE");
									
									if (oweItem[i].getCERTIFICATE_TYPE() == null|| oweItem[i].getCERTIFICATE_TYPE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCERTIFICATE_TYPE());
										
									}
									
									oweItemE = OWE_ITEM.addElement("CERTIFICATE_NO");
									if (oweItem[i].getCERTIFICATE_NO() == null|| oweItem[i].getCERTIFICATE_NO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCERTIFICATE_NO());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_NAME");
									if (oweItem[i].getACCT_NAME() == null|| oweItem[i].getACCT_NAME().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_NAME());
									}
									
									oweItemE = OWE_ITEM.addElement("ACC_NBR");
									if (oweItem[i].getACC_NBR() == null|| oweItem[i].getACC_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACC_NBR());
									}
									
									oweItemE = OWE_ITEM.addElement("SERV_ID");
									if (oweItem[i].getSERV_ID() == null|| oweItem[i].getSERV_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSERV_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("REGION_ID");
									if (oweItem[i].getREGION_ID() == null|| oweItem[i].getREGION_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getREGION_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("SERV_TOTAL_OWE");
									if (oweItem[i].getSERV_TOTAL_OWE() == null|| oweItem[i].getSERV_TOTAL_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSERV_TOTAL_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_ID");
									if (oweItem[i].getACCT_ID() == null|| oweItem[i].getACCT_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_TOTAL_OWE");
									if (oweItem[i].getACCT_TOTAL_OWE() == null|| oweItem[i].getACCT_TOTAL_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_TOTAL_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_BAD_OWE");
									if (oweItem[i].getACCT_BAD_OWE() == null|| oweItem[i].getACCT_BAD_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_BAD_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ONCE_OWE");
									if (oweItem[i].getONCE_OWE() == null|| oweItem[i].getONCE_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getONCE_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ITEM_OWE");
									if (oweItem[i].getITEM_OWE() == null|| oweItem[i].getITEM_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getITEM_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("CAN_RECHARGE");
									if (oweItem[i].getCAN_RECHARGE() == null|| oweItem[i].getCAN_RECHARGE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCAN_RECHARGE());
									}
									serviceInformation.add(OWE_ITEM);
									logger.info("=============oweItemE========" +oweItemE.asXML());
									logger.info("=============serviceInformation========" +serviceInformation.asXML());
								}
							}else if(result==-1){
								logger.info("==============result========" + result);
								String errInfo = resp.getERR_INFO();
								Element element = serviceInformation.addElement("Result");
								element.setText("0");
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("ERR_INFO");
								if (errInfo == null|| errInfo.equals("	")) {
										element.setText("	");
									} else {
										element.setText(errInfo);
									}
							}
						}else {
							PayOtherLatnProxy proxy = new PayOtherLatnProxy( url);
							QueryBlackOweRequest queryBlackOweRequest = new QueryBlackOweRequest();
							queryBlackOweRequest.setCERTIFICATE_NO(certificateNo);
							queryBlackOweRequest.setCERTIFICATE_TYPE(certificateType);
							queryBlackOweRequest.setCHANNEL_CODE(channelCode);
							queryBlackOweRequest.setREGION_ID(areaCode);
							queryBlackOweRequest.setSTAFF_ID(staffId);
							logger.info("==============before=======" );
							QueryBlackOweResponse resp = proxy.queryBlackOwe(queryBlackOweRequest);
							logger.info("==============after========" );
							
							if(resp.getRESULT()==0){
								 result = resp.getRESULT();
								logger.info("==============result========" + result);
								String errInfo = resp.getERR_INFO();
								logger.info("==============errInfo========" + errInfo);
								OweItem [] oweItem=resp.getOWE_ITEM();
								logger.info("==============oi.length========" + oweItem.length);
							
								Element element = serviceInformation.addElement("Result");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								
								element = serviceInformation.addElement("ERR_INFO");
								if (errInfo == null|| errInfo.equals("	")) {
										element.setText("	");
									} else {
										element.setText(errInfo);
									}
								
								for (int i = 0; i < oweItem.length; i++) {
									logger.info("=============进入for========"+i );
									OWE_ITEM = DocumentHelper.createElement("OWE_ITEM");
									
									
									Element oweItemE= OWE_ITEM.addElement("CERTIFICATE_TYPE");
									
									if (oweItem[i].getCERTIFICATE_TYPE() == null|| oweItem[i].getCERTIFICATE_TYPE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCERTIFICATE_TYPE());
										
									}
									
									oweItemE = OWE_ITEM.addElement("CERTIFICATE_NO");
									if (oweItem[i].getCERTIFICATE_NO() == null|| oweItem[i].getCERTIFICATE_NO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCERTIFICATE_NO());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_NAME");
									if (oweItem[i].getACCT_NAME() == null|| oweItem[i].getACCT_NAME().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_NAME());
									}
									
									oweItemE = OWE_ITEM.addElement("ACC_NBR");
									if (oweItem[i].getACC_NBR() == null|| oweItem[i].getACC_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACC_NBR());
									}
									
									oweItemE = OWE_ITEM.addElement("SERV_ID");
									if (oweItem[i].getSERV_ID() == null|| oweItem[i].getSERV_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSERV_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("REGION_ID");
									if (oweItem[i].getREGION_ID() == null|| oweItem[i].getREGION_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getREGION_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("SERV_TOTAL_OWE");
									if (oweItem[i].getSERV_TOTAL_OWE() == null|| oweItem[i].getSERV_TOTAL_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSERV_TOTAL_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_ID");
									if (oweItem[i].getACCT_ID() == null|| oweItem[i].getACCT_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_TOTAL_OWE");
									if (oweItem[i].getACCT_TOTAL_OWE() == null|| oweItem[i].getACCT_TOTAL_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_TOTAL_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_BAD_OWE");
									if (oweItem[i].getACCT_BAD_OWE() == null|| oweItem[i].getACCT_BAD_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_BAD_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ONCE_OWE");
									if (oweItem[i].getONCE_OWE() == null|| oweItem[i].getONCE_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getONCE_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("ITEM_OWE");
									if (oweItem[i].getITEM_OWE() == null|| oweItem[i].getITEM_OWE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getITEM_OWE());
									}
									
									oweItemE = OWE_ITEM.addElement("CAN_RECHARGE");
									if (oweItem[i].getCAN_RECHARGE() == null|| oweItem[i].getCAN_RECHARGE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getCAN_RECHARGE());
									}
									serviceInformation.add(OWE_ITEM);
									logger.info("=============oweItemE========" +oweItemE.asXML());
									logger.info("=============serviceInformation========" +serviceInformation.asXML());
								}
							}else if(result==-1){
								logger.info("==============result========" + result);
								String errInfo = resp.getERR_INFO();
								Element element = serviceInformation.addElement("Result");
								element.setText("0");
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("ERR_INFO");
								if (errInfo == null|| errInfo.equals("	")) {
										element.setText("	");
									} else {
										element.setText(errInfo);
									}
							}
						}
						
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(result);
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
						
						tmallLogDao.insertBusinessRecordPort(bean);
						
						XmlMessage ack = new XmlMessage(true);
						ack.setMID(reqXmlMessage.getMID());
						ack.setREPTAG(0);
						ack.setRTT(String.valueOf(receiveTime));
						ack.setSIG(null);
						ack.setRC("0");
						ack.setDS("SUCCESS");
						ack.setDATA(serviceInformation.asXML());
						String respXML = convertResponseString(ack);
						logger.info("=======================respXML========================");
						logger.info(respXML);
						logger.info("=======================respXML========================");
						byte[] resps = respXML.getBytes("UTF-8");
						ack.setLength(resps.length);
						ack.setMsgTime(System.currentTimeMillis());
						body.write(resps);
						body.close();

					}

////////////////////////拆机用户缴费PayBlackOwe.HB//////////////////////////////////////////
					//拆机用户黑名单缴费
			 else if (reqXmlMessage.getSCID().equals("PayBlackOwe.HB@027.ctnbc-bon.net")) {
					logger.info("======PayBlackOwe.HB.getDATA()======"+ reqXmlMessage.getDATA());
					Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					String certificateType = (String) map.get("CERTIFICATE_TYPE");
					logger.info("==============certificateType========" + certificateType);
					String certificateNo = (String) map.get("CERTIFICATE_NO");
					logger.info("==============certificateNo========" + certificateNo);
					String accNbr = (String) map.get("ACC_NBR");
					logger.info("==============accNbr========" + accNbr);
					String acctId = (String) map.get("ACCT_ID");
					logger.info("==============acctId========" + acctId);
					String servId = (String) map.get("SERV_ID");
					logger.info("==============servId========" + servId);
					String regionIdAcct = (String) map.get("REGION_ID_ACCT");
					logger.info("==============regionIdAcct========" + regionIdAcct);
					String totalAmount = (String) map.get("TOTAL_AMOUNT");
					logger.info("==============totalAmount========" + totalAmount);
					String blackAmount = (String) map.get("BLACK_AMOUNT");
					logger.info("==============blackAmount========" + blackAmount);
					String normalAmount = (String) map.get("NORMAL_AMOUNT");
					logger.info("==============normalAmount========" + normalAmount);
					String channelCode = (String) map.get("CHANNEL_CODE");
					logger.info("==============channelCode========" + channelCode);
					String areaCode = (String) map.get("AREA_CODE");
					logger.info("==============areaCode========" + areaCode);
					String regionId =null;
					if(map.containsKey("regionId")){
						regionId = (String) map.get("REGION_ID");
					}else{
						regionId = regionIdAcct;
					}
					logger.info("==============regionId========" + regionId);
					
					String staffId=null;
					if(map.containsKey("staffId")){
						staffId = (String) map.get("STAFF_ID");
					}else{
						staffId = " ";
					}
					logger.info("==============staffId========" + staffId);
					String siteId=null;
					if(map.containsKey("siteId")){
						siteId = (String) map.get("SITE_ID");
					}else{
						siteId = " ";
					}
					logger.info("==============siteId========" + siteId);
					String ifInvoicePrint = (String) map.get("IF_INVOICE_PRINT");
					logger.info("==============ifInvoicePrint========" + ifInvoicePrint);
					
					String url = null;
					 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
					int urlForJf3 = getURLForJf3(areaCode,IS_WH);
					switch (urlForJf3) {
					case 1://新武汉
						url = PayBlackOweWHjf3;
						break;
					case 2://新湖北
						url = PayBlackOweHBjf3;
						break;
					case 3://旧武汉
						url = PayBlackOweWH;
						break;
					case 4://旧湖北
						url = PayBlackOweHB;
						break;
						
					default:
						break;
					}
					logger.info("========|=======调用地址url============" + url);
					int result =-1;
					String errInfo=null;
					String operSerialNbr=null;
					if(urlForJf3 == 1 || urlForJf3 == 2) {
						logger.info("==============进入新接口======urlForJf3:"+urlForJf3 );
						BillingBossServiceImplServiceSoapBindingStub stu  = new BillingBossServiceImplServiceSoapBindingStub(new java.net.URL(url),null);
						com.asiainfo.webservice.PayBlackOweRequest payBlackOweRequest =new com.asiainfo.webservice.PayBlackOweRequest();
						payBlackOweRequest.setCERTIFICATE_NO(certificateNo);
						payBlackOweRequest.setCERTIFICATE_TYPE(certificateType);
						payBlackOweRequest.setACC_NBR(accNbr);
						payBlackOweRequest.setACCT_ID(acctId);
						payBlackOweRequest.setSERV_ID(servId);
						payBlackOweRequest.setREGION_ID_ACCT(regionIdAcct);
						payBlackOweRequest.setTOTAL_AMOUNT(totalAmount);
						payBlackOweRequest.setBLACK_AMOUNT(blackAmount);
						payBlackOweRequest.setNORMAL_AMOUNT(normalAmount);
						payBlackOweRequest.setCHANNEL_CODE(channelCode);
						payBlackOweRequest.setREGION_ID(regionId);
						payBlackOweRequest.setSTAFF_ID(staffId);
						payBlackOweRequest.setSITE_ID(siteId);
						payBlackOweRequest.setIF_INVOICE_PRINT(ifInvoicePrint);
						payBlackOweRequest.setAREA_CODE(areaCode);
						com.asiainfo.webservice.PayBlackOweResponse resp = stu.payBlackOwe(payBlackOweRequest);
						 result = resp.getRESULT();
						 errInfo = resp.getERR_INFO();
						 operSerialNbr=resp.getOPER_SERIAL_NBR();
					}else {
						PayOtherLatnProxy proxy = new PayOtherLatnProxy(url);
						PayBlackOweRequest payBlackOweRequest = new PayBlackOweRequest();
						payBlackOweRequest.setCERTIFICATE_NO(certificateNo);
						payBlackOweRequest.setCERTIFICATE_TYPE(certificateType);
						payBlackOweRequest.setACC_NBR(accNbr);
						payBlackOweRequest.setACCT_ID(acctId);
						payBlackOweRequest.setSERV_ID(servId);
						payBlackOweRequest.setREGION_ID_ACCT(regionIdAcct);
						payBlackOweRequest.setTOTAL_AMOUNT(totalAmount);
						payBlackOweRequest.setBLACK_AMOUNT(blackAmount);
						payBlackOweRequest.setNORMAL_AMOUNT(normalAmount);
						payBlackOweRequest.setCHANNEL_CODE(channelCode);
						payBlackOweRequest.setREGION_ID(regionId);
						payBlackOweRequest.setSTAFF_ID(staffId);
						payBlackOweRequest.setSITE_ID(siteId);
						payBlackOweRequest.setIF_INVOICE_PRINT(ifInvoicePrint);
						payBlackOweRequest.setAREA_CODE(areaCode);
						PayBlackOweResponse resp= proxy.payBlackOwe(payBlackOweRequest);
						 result = resp.getRESULT();
						 errInfo = resp.getERR_INFO();
						 operSerialNbr=resp.getOPER_SERIAL_NBR();
					}
					logger.info("==============result========" + result);
					logger.info("==============errInfo========" + errInfo);
					logger.info("==============operSerialNbr========" + operSerialNbr);

					Element serviceInformation = DocumentHelper.createElement("Service_Information");
					Element element = serviceInformation.addElement("Result");
					element.setText(String.valueOf(result));
					element = serviceInformation.addElement("RESULT");
					element.setText(String.valueOf(result));
					
					element = serviceInformation.addElement("ERR_INFO");
					if (errInfo == null|| errInfo.equals("	")) {
							element.setText("	");
						} else {
							element.setText(errInfo);
						}
					
					element = serviceInformation.addElement("OPER_SERIAL_NBR");
					if (operSerialNbr == null|| operSerialNbr.equals("	")) {
							element.setText("	");
						} else {
							element.setText(operSerialNbr);
						}
					
					
					BusinessRecordPort bean= new BusinessRecordPort();
					bean.setSessionId(reqXmlMessage.getMID());
					bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
							.currentTimeMillis()));
					bean.setRequestHost(reqXmlMessage.getUID());
					bean.setServiceContextId(reqXmlMessage.getSCID());
					bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
							.currentTimeMillis()));
					bean.setResult(result);
					TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
					
					tmallLogDao.insertBusinessRecordPort(bean);
					
					XmlMessage ack = new XmlMessage(true);
					ack.setMID(reqXmlMessage.getMID());
					ack.setREPTAG(0);
					ack.setRTT(String.valueOf(receiveTime));
					ack.setSIG(null);
					ack.setRC("0");
					ack.setDS("SUCCESS");
					ack.setDATA(serviceInformation.asXML());
					String respXML = convertResponseString(ack);
					logger.info("=======================respXML========================");
					logger.info(respXML);
					logger.info("=======================respXML========================");
					byte[] resps = respXML.getBytes("UTF-8");
					ack.setLength(resps.length);
					ack.setMsgTime(System.currentTimeMillis());
					body.write(resps);
					body.close();

				}
////////////////////////电子发票推送PushNetInvoice.HB//////////////////////////////////////////
					
	 else if (reqXmlMessage.getSCID().equals("PushNetInvoice.HB@027.ctnbc-bon.net")) {
			logger.info("======PushNetInvoice.HB.getDATA()======"+ reqXmlMessage.getDATA());
			Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
			
			String invoiceId = (String) map.get("INVOICE_ID");
			logger.info("==============invoiceId========" + invoiceId);
			
			
			String areaCode = (String) map.get("AREA_CODE");
			logger.info("==============areaCode========" + areaCode);
			
			String url = null;
			 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
			int urlForJf3 = getURLForJf3(areaCode,IS_WH);
			switch (urlForJf3) {
			case 1://新武汉
				url = QueryNetInvoiceWHjf3;
				break;
			case 2://新湖北
				url = QueryNetInvoiceHBjf3;
				break;
			case 3://旧武汉
				url = QueryNetInvoiceWH;
				break;
			case 4://旧湖北
				url = QueryNetInvoiceHB;
				break;
				
			default:
				break;
			}
			logger.info("===============调用地址url============" + url);
			String resultInfo = null;
			int result=-1;
			if(urlForJf3 == 1 || urlForJf3 == 2) {
				logger.info("==============进入新接口======urlForJf3:"+urlForJf3 );
				BillingBossServiceImplServiceSoapBindingStub stu  = new BillingBossServiceImplServiceSoapBindingStub(new java.net.URL(url),null);
				com.asiainfo.webservice.PushNetInvoiceRequest param=new com.asiainfo.webservice.PushNetInvoiceRequest();
				param.setINVOICE_ID(invoiceId);
				com.asiainfo.webservice.PushNetInvoiceResponse resp = stu.pushNetInvoice(param);
				 result = resp.getRESULT();
				logger.info("==============result========" + result);
				 resultInfo = resp.getRESULTINFO();
				logger.info("==============resultInfo========" + resultInfo);
			}else {
				BossServicePortTypeYGZProxy proxy = new BossServicePortTypeYGZProxy(url);
				PushNetInvoiceRequest pushNetInvoiceRequest = new PushNetInvoiceRequest();
				pushNetInvoiceRequest.setINVOICE_ID(invoiceId);
				logger.info("==============before=======" );
				PushNetInvoiceResponse resp= proxy.pushNetInvoice(pushNetInvoiceRequest);
				logger.info("==============after========" );
				 result = resp.getRESULT();
				logger.info("==============result========" + result);
				 resultInfo = resp.getRESULTINFO();
				logger.info("==============resultInfo========" + resultInfo);
			}
			Element serviceInformation = DocumentHelper.createElement("Service_Information");
			Element element = serviceInformation.addElement("Result");
			element.setText(String.valueOf(result));
			element = serviceInformation.addElement("RESULT");
			element.setText(String.valueOf(result));
			
			element = serviceInformation.addElement("RESULTINFO");
			if (resultInfo == null|| resultInfo.equals("	")) {
					element.setText("	");
				} else {
					element.setText(new String(resultInfo.getBytes(), "utf-8"));
				}
			
			BusinessRecordPort bean= new BusinessRecordPort();
			bean.setSessionId(reqXmlMessage.getMID());
			bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System.currentTimeMillis()));
			bean.setRequestHost(reqXmlMessage.getUID());
			bean.setServiceContextId(reqXmlMessage.getSCID());
			bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()));
			bean.setResult(result);
			TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
			
			tmallLogDao.insertBusinessRecordPort(bean);
			
			XmlMessage ack = new XmlMessage(true);
			ack.setMID(reqXmlMessage.getMID());
			ack.setREPTAG(0);
			ack.setRTT(String.valueOf(receiveTime));
			ack.setSIG(null);
			ack.setRC("0");
			ack.setDS("SUCCESS");
			ack.setDATA(serviceInformation.asXML());
			String respXML = convertResponseString(ack);
			logger.info("=======================respXML========================");
			logger.info(respXML);
			logger.info("=======================respXML========================");
			byte[] resps = respXML.getBytes("UTF-8");
			ack.setLength(resps.length);
			ack.setMsgTime(System.currentTimeMillis());
			body.write(resps);
			body.close();

		}	

////////////////////////电子发票开票DrawNetInvoice.HB//////////////////////////////////////////
				
		 else if (reqXmlMessage.getSCID().equals("DrawNetInvoice.HB@027.ctnbc-bon.net")) {
			 
				logger.info("======DrawNetInvoice.HB.getDATA()======"+ reqXmlMessage.getDATA());
				Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
				
				String invoiceId = (String) map.get("INVOICE_ID");
				logger.info("==============invoiceId========" + invoiceId);
				
				
				String areaCode = (String) map.get("AREA_CODE");
				logger.info("==============areaCode========" + areaCode);

				
				String url = null;
				 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
				int urlForJf3 = getURLForJf3(areaCode,IS_WH);
				switch (urlForJf3) {
				case 1://新武汉
					url = QueryNetInvoiceWHjf3;
					break;
				case 2://新湖北
					url = QueryNetInvoiceHBjf3;
					break;
				case 3://旧武汉
					url = QueryNetInvoiceWH;
					break;
				case 4://旧湖北
					url = QueryNetInvoiceHB;
					break;
					
				default:
					break;
				}
				logger.info("===============调用地址url============" + url);
				String resultInfo = null;
				int result=-1;
				if(urlForJf3 == 1 || urlForJf3 == 2) {
					logger.info("==============进入新接口======urlForJf3:"+urlForJf3 );
					BillingBossServiceImplServiceSoapBindingStub stu  = new BillingBossServiceImplServiceSoapBindingStub(new java.net.URL(url),null);
					com.asiainfo.webservice.DrawNetInvoiceRequest param=new com.asiainfo.webservice.DrawNetInvoiceRequest();
					param.setINVOICE_ID(invoiceId);
					com.asiainfo.webservice.DrawNetInvoiceResponse resp = stu.drawNetInvoice(param);
					 result = resp.getRESULT();
					logger.info("==============result========" + result);
					 resultInfo = resp.getRESULTINFO();
					logger.info("==============resultInfo========" + resultInfo);
				}else {
					BossServicePortTypeYGZProxy proxy = new BossServicePortTypeYGZProxy(url);
					DrawNetInvoiceRequest drawNetInvoiceRequest = new DrawNetInvoiceRequest();
					drawNetInvoiceRequest.setINVOICE_ID(invoiceId);
					logger.info("==============before=======" );
					DrawNetInvoiceResponse resp= proxy.drawNetInvoice(drawNetInvoiceRequest);
					logger.info("==============after========" );
					 result = resp.getRESULT();
					logger.info("==============result========" + result);
					 resultInfo = resp.getRESULTINFO();
					logger.info("==============resultInfo========" + resultInfo);
				}
				

				Element serviceInformation = DocumentHelper.createElement("Service_Information");
				Element element = serviceInformation.addElement("Result");
				element.setText(String.valueOf(result));
				element = serviceInformation.addElement("RESULT");
				element.setText(String.valueOf(result));
				
				element = serviceInformation.addElement("RESULTINFO");
				if (resultInfo == null|| resultInfo.equals("	")) {
						element.setText("	");
				} else {
					element.setText(new String(resultInfo.getBytes("ISO-8859-1"), "UTF-8"));
				}
				
				BusinessRecordPort bean= new BusinessRecordPort();
				bean.setSessionId(reqXmlMessage.getMID());
				bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
						.currentTimeMillis()));
				bean.setRequestHost(reqXmlMessage.getUID());
				bean.setServiceContextId(reqXmlMessage.getSCID());
				bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
						.currentTimeMillis()));
				bean.setResult(result);
				TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
				
				tmallLogDao.insertBusinessRecordPort(bean);
				
				XmlMessage ack = new XmlMessage(true);
				ack.setMID(reqXmlMessage.getMID());
				ack.setREPTAG(0);
				ack.setRTT(String.valueOf(receiveTime));
				ack.setSIG(null);
				ack.setRC("0");
				ack.setDS("SUCCESS");
				ack.setDATA(serviceInformation.asXML());
				String respXML = convertResponseString(ack);
				logger.info("=======================respXML========================");
				logger.info(respXML);
				logger.info("=======================respXML========================");
				byte[] resps = respXML.getBytes("UTF-8");
				ack.setLength(resps.length);
				ack.setMsgTime(System.currentTimeMillis());
				body.write(resps);
				body.close();
			}
			else if (reqXmlMessage.getSCID().equals("CheckOrderCharge.HB@027.ctnbc-bon.net")) {
				TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
				try {
					Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					String regionId = (String) map.get("regionId");
					logger.info("==============regionId========" + regionId);
					String acctId = (String) map.get("salesIndentId");
					logger.info("==============acctId========" + acctId);
					String itemIdList = (String) map.get("itemIdList");
					logger.info("==============itemIdList========" + itemIdList);
					
					
					String url="";
					if (regionId.equals("1001")) {
						url = OrderChargeURL;
					} else {
						url = OrderChargeURLHB;
					}
					logger.info("==============url========" + url);
					CheckOrderChargeRequest chargeRequest =new CheckOrderChargeRequest();
					chargeRequest.setRegionId(Integer.valueOf(regionId));
					chargeRequest.setSalesIndentId(acctId);
					chargeRequest.setItemIdList(itemIdList);
					BossServicePortTypeProxy proxy = new BossServicePortTypeProxy(url);
					CheckOrderChargeResponse resp = proxy.checkOrderCharge(chargeRequest);
					
					Element serviceInformation = DocumentHelper.createElement("Service_Information");
					
					
					if(resp!=null&&resp.getResult()==0){
						Element element = serviceInformation.addElement("Result");
						element.setText(String.valueOf(resp.getResult()));
						logger.info("==============Result========" + resp.getResult());
						element = serviceInformation.addElement("result");
						element.setText(String.valueOf(resp.getResult()));
						element = serviceInformation.addElement("resultInfo");
						element.setText(resp.getResultInfo());
						logger.info("==============resultInfo========" + resp.getResultInfo());
						element = serviceInformation.addElement("rawCharge");
						element.setText(String.valueOf(resp.getRawCharge()));
						logger.info("==============rawCharge========" + resp.getRawCharge());
						element = serviceInformation.addElement("realChare");
						element.setText(String.valueOf(resp.getRealChare()));
						logger.info("==============realChare========" + resp.getRealChare());
						
						
						if(resp.getItem()!=null){
							Element element2 =null;
							Element Item =null;
								
							for (CheckOrderChargeResponseItem item : resp.getItem()) {
								Item = serviceInformation.addElement("Item");
								element2 =Item.addElement("itemId");
								element2.setText(item.getItemId());
								logger.info("==============itemId========" + item.getItemId());
								element2 =Item.addElement("itemType");
								element2.setText(String.valueOf(item.getItemType()));
								logger.info("==============itemType========" + item.getItemType());
								element2 =Item.addElement("itemCharge");
								element2.setText(String.valueOf(item.getItemCharge()));
								logger.info("==============itemCharge========" + item.getItemCharge());
								element2 =Item.addElement("itemRealCharge");
								element2.setText(String.valueOf(item.getItemRealCharge()));
								logger.info("==============itemRealCharge========" + item.getItemRealCharge());
							}
						}
						
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(0);
						
						tmallLogDao.insertBusinessRecordPort(bean);
					}else{
						Element element = serviceInformation.addElement("Result");
						element.setText("1");
						element = serviceInformation.addElement("result");
						if(resp!=null){
							logger.info("==============result========" + resp.getResult());
							element.setText(String.valueOf(resp.getResult()));
						}else{
							logger.info("==============result is null========");
							element.setText("");
						}
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(-1);
						bean.setResultReason("-1");
						tmallLogDao.insertBusinessRecordPort(bean);	
						
					}
					
					
					XmlMessage ack = new XmlMessage(true);
					ack.setMID(reqXmlMessage.getMID());
					ack.setREPTAG(0);
					ack.setRTT(String.valueOf(receiveTime));
					ack.setSIG(null);
					ack.setRC("0");
					ack.setDS("SUCCESS");
					ack.setDATA(serviceInformation.asXML());
					String respXML = convertResponseString(ack);
					logger.info("=======================respXML========================");
					logger.info(respXML);
					logger.info("=======================respXML========================");
					byte[] resps = respXML.getBytes("UTF-8");
					ack.setLength(resps.length);
					ack.setMsgTime(System.currentTimeMillis());
					body.write(resps);
					body.close();
				} catch (Exception e) {
					logger.warn("Exception:" + e.getMessage()+"MID:"+reqXmlMessage.getMID());
					
					Element serviceInformation = DocumentHelper.createElement("Service_Information");
					Element element = serviceInformation.addElement("Result");
					element.setText("1");
					element = serviceInformation.addElement("result");
					element.setText("10076");
					
					XmlMessage ack = new XmlMessage(true);
					ack.setMID(reqXmlMessage.getMID());
					ack.setREPTAG(0);
					ack.setRTT(String.valueOf(receiveTime));
					ack.setSIG(null);
					ack.setRC("0");
					ack.setDS("SUCCESS");
					ack.setDATA(serviceInformation.asXML());
					String respXML = convertResponseString(ack);
					logger.info("=======================respXML========================");
					logger.info(respXML);
					logger.info("=======================respXML========================");
					byte[] resps = respXML.getBytes("UTF-8");
					ack.setLength(resps.length);
					ack.setMsgTime(System.currentTimeMillis());
					body.write(resps);
					body.close();
					
					BusinessRecordPort bean= new BusinessRecordPort();
					bean.setSessionId(reqXmlMessage.getMID());
					bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
							.currentTimeMillis()));
					bean.setRequestHost(reqXmlMessage.getUID());
					bean.setServiceContextId(reqXmlMessage.getSCID());
					bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
							.currentTimeMillis()));
					bean.setResult(1);
					bean.setResultCode(10076);
					tmallLogDao.insertBusinessRecordPort(bean);
					
					return;
				}
				
			}
			else if (reqXmlMessage.getSCID().equals("CancelOrderCharge.HB@027.ctnbc-bon.net")) {
				TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
				try{
					Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					String regionId = (String) map.get("regionId");
					logger.info("==============regionId========" + regionId);
					String acctId = (String) map.get("salesIndentId");
					logger.info("==============acctId========" + acctId);
					String itemIdList = (String) map.get("itemIdList");
					logger.info("==============itemIdList========" + itemIdList);
					String staffId = (String) map.get("staffId");
					logger.info("==============staffId========" + staffId);
					
					CancelOrderChargeRequest chargeRequest =new CancelOrderChargeRequest();
					chargeRequest.setRegionId(Integer.valueOf(regionId));
					chargeRequest.setSalesIndentId(acctId);
					chargeRequest.setItemIdList(itemIdList);
					chargeRequest.setStaffId(staffId);
					
					String url="";
					if (regionId.equals("1001")) {
						url = OrderChargeURL;
					} else {
						url = OrderChargeURLHB;
					}
					logger.info("==============url========" + url);
					BossServicePortTypeProxy proxy = new BossServicePortTypeProxy(url);
					CancelOrderChargeResponse resp = proxy.cancelOrderCharge(chargeRequest);
					
					Element serviceInformation = DocumentHelper.createElement("Service_Information");
					
					if(resp!=null&&resp.getResult()==0){
						logger.info("==============result========" + resp.getResult());
						
						Element element = serviceInformation.addElement("Result");
						element.setText(String.valueOf(resp.getResult()));
						logger.info("==============Result========" + resp.getResult());
						element = serviceInformation.addElement("result");
						element.setText(String.valueOf(resp.getResult()));
						element = serviceInformation.addElement("resultCode");
						element.setText(String.valueOf(resp.getResultCode()));
						logger.info("==============resultCode========" + resp.getResultCode());
						element = serviceInformation.addElement("resultInfo");
						element.setText(resp.getResultInfo());
						logger.info("==============resultInfo========" + resp.getResultInfo());
						element = serviceInformation.addElement("rawCharge");
						element.setText(String.valueOf(resp.getRawCharge()));
						logger.info("==============rawCharge========" + resp.getRawCharge());
						element = serviceInformation.addElement("realChare");
						element.setText(String.valueOf(resp.getRealChare()));
						logger.info("==============realChare========" + resp.getRealChare());
						
						if(resp.getItem()!=null){
							Element element2 =null;
							Element Item =null;
								
							for (CancelOrderChargeResponseItem item : resp.getItem()) {
								Item = serviceInformation.addElement("Item");
								element2 =Item.addElement("itemId");
								element2.setText(item.getItemId());
								logger.info("==============itemId========" + item.getItemId());
								element2 =Item.addElement("itemType");
								element2.setText(String.valueOf(item.getItemType()));
								logger.info("==============itemType========" + item.getItemType());
								element2 =Item.addElement("itemCharge");
								element2.setText(String.valueOf(item.getItemCharge()));
								logger.info("==============itemCharge========" + item.getItemCharge());
								element2 =Item.addElement("itemRealCharge");
								element2.setText(String.valueOf(item.getItemRealCharge()));
								logger.info("==============itemRealCharge========" + item.getItemRealCharge());
							}
						}
						
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(0);
						
						tmallLogDao.insertBusinessRecordPort(bean);
					}else{
						
						Element element = serviceInformation.addElement("Result");
						element.setText("1");
						element = serviceInformation.addElement("result");
						if(resp!=null){
							logger.info("==============result========" + resp.getResult());
							element.setText(String.valueOf(resp.getResult()));
						}else{
							logger.info("==============result is null========");
							element.setText("");
						}
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(-1);
						bean.setResultReason("-1");
						tmallLogDao.insertBusinessRecordPort(bean);	
					}
					XmlMessage ack = new XmlMessage(true);
					ack.setMID(reqXmlMessage.getMID());
					ack.setREPTAG(0);
					ack.setRTT(String.valueOf(receiveTime));
					ack.setSIG(null);
					ack.setRC("0");
					ack.setDS("SUCCESS");
					ack.setDATA(serviceInformation.asXML());
					String respXML = convertResponseString(ack);
					logger.info("=======================respXML========================");
					logger.info(respXML);
					logger.info("=======================respXML========================");
					byte[] resps = respXML.getBytes("UTF-8");
					ack.setLength(resps.length);
					ack.setMsgTime(System.currentTimeMillis());
					body.write(resps);
					body.close();
				 } catch (Exception e) {
					 	logger.warn("Exception:" + e.getMessage()+"MID:"+reqXmlMessage.getMID());
						Element serviceInformation = DocumentHelper.createElement("Service_Information");
						Element element = serviceInformation.addElement("Result");
						element.setText("1");
						element = serviceInformation.addElement("result");
						element.setText("10076");
						
						XmlMessage ack = new XmlMessage(true);
						ack.setMID(reqXmlMessage.getMID());
						ack.setREPTAG(0);
						ack.setRTT(String.valueOf(receiveTime));
						ack.setSIG(null);
						ack.setRC("0");
						ack.setDS("SUCCESS");
						ack.setDATA(serviceInformation.asXML());
						String respXML = convertResponseString(ack);
						logger.info("=======================respXML========================");
						logger.info(respXML);
						logger.info("=======================respXML========================");
						byte[] resps = respXML.getBytes("UTF-8");
						ack.setLength(resps.length);
						ack.setMsgTime(System.currentTimeMillis());
						body.write(resps);
						body.close();
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(1);
						bean.setResultCode(10076);
						tmallLogDao.insertBusinessRecordPort(bean);
						
						return;
					}
			}
					//2.2.2.4断网查询
			else if (reqXmlMessage.getSCID().equals("QueryStopNet.HB@027.ctnbc-bon.net")) {
				 logger.info("======QueryStopNet.HB.getDATA()======"+ reqXmlMessage.getDATA());
				 
				 Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
				 String accNbr = (String) map.get("ACC_NBR");
				 String regionId = (String) map.get("REGION_ID");
				 String url = null;
				 
				 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
				 int urlForJf3 = getURLForJf3(regionId,IS_WD);
				switch (urlForJf3) {
				case 1://新武汉
					url = QueryStopNetWHjf3;
					break;
				case 2://新湖北
					url = QueryStopNetHBjf3;
					break;
				case 3://旧武汉
					url = QueryStopNetWH;
					break;
				case 4://旧湖北
					url = QueryStopNetHB;
					break;
					
				default:
					break;
				}
				 //String url = regionId.equals(IS_WD) ? QueryStopNetWH : QueryStopNetHB;
				 logger.info("======OutBlockUp.HB.getDATA()======"+ reqXmlMessage.getDATA());
				 //得到发送webservice请求的信息
				 StringBuffer para;
				 PostMethod post = new PostMethod(url);
				 if(urlForJf3 == 1 || urlForJf3 == 2) {
					  para = getQueryStopWebServiceInfoNew(accNbr, regionId);
				 }else {
					  para = getQueryStopWebServiceInfo(accNbr, regionId);
					 post.setRequestHeader("SOAPAction", "");
				 }
				 logger.info("===============调用地址url============" + url);
				 logger.info("===============发到下游的消息============" + para.toString());
				 
				 String resp = "";
				 //得到下游返回的信息
				 StringBuffer resBuffer = getResponseMessage(para, post);  
				 resp = resBuffer.toString();
				 logger.info("===============下游返回的消息============" + resp);
				 String data = "";
				 int retCode = 0;
				 String errMes = "";
				 StringBuffer stringBuffer = null;
				 if(resBuffer.length() == 0 ) {
					 stringBuffer = new StringBuffer();
					 stringBuffer.append("<Service_Information>");
					 stringBuffer.append("<retCode>");
					 stringBuffer.append(TIMEOUT);
					 stringBuffer.append("</retCode>");
					 stringBuffer.append("<errMsg>");
					 stringBuffer.append("请求超时");
					 stringBuffer.append("</errMsg>");
					 stringBuffer.append("</Service_Information>");
					 retCode = TIMEOUT;
					 errMes = "请求超时";
				 } else {
						try {
							 logger.info("----66666666----");
							 if(urlForJf3 == 1 || urlForJf3 == 2) {
								 //新流程新解析
								 retCode=Integer.valueOf(resp.substring(resp.indexOf("<Result>")+8, resp.indexOf("</Result>")));
								 String resultInfoStr=resp.substring(resp.indexOf("<Result_Info>")+13, resp.indexOf("</Result_Info>"));
								 String stopStateStr=resp.substring(resp.indexOf("<Stop_State>")+12, resp.indexOf("</Stop_State>"));
								 String operDateStr=resp.substring(resp.indexOf("<Oper_Date>")+11, resp.indexOf("</Oper_Date>"));
								 errMes = resultInfoStr;
								 stringBuffer = new StringBuffer();
								 stringBuffer.append("<Service_Information>");
								 stringBuffer.append("<RESULT>");
								 stringBuffer.append(retCode);
								 stringBuffer.append("</RESULT>");
								 stringBuffer.append("<RESULT_INFO>");
								 stringBuffer.append(resultInfoStr);
								 stringBuffer.append("</RESULT_INFO>");
								 stringBuffer.append("<STOP_STATE>");
								 stringBuffer.append(stopStateStr);
								 stringBuffer.append("</STOP_STATE>");
								 stringBuffer.append("<OPER_DATE>");
								 stringBuffer.append(operDateStr);
								 stringBuffer.append("</OPER_DATE>");
								 stringBuffer.append("</Service_Information>");
							 }else {
								 data = parseQueryStopReturnObur(resp);
								 logger.info("data" +data);
								 Document doc = DocumentHelper.parseText(data);
								 List<org.dom4j.Node> nodes=doc.selectNodes("//QueryStopNetResponse");
								 logger.info("nodes" +nodes.size());
								 String resultInfoStr = "";
								 String stopStateStr = "";
								 String operDateStr = "";
								 String resultStr = "";
								 for (org.dom4j.Node node : nodes) {
									Element e=(Element)node;
									Element resultInfo=e.element("RESULT_INFO");
									Element result=e.element("RESULT");
									Element stopState=e.element("STOP_STATE");
									Element operDate=e.element("OPER_DATE");
									resultInfoStr = resultInfo.getText();
									stopStateStr = stopState.getText();
									operDateStr = operDate.getText();
									resultStr = result.getText();
									retCode = Integer.parseInt(resultStr); 
									errMes = resultInfoStr;
								 }
								 stringBuffer = new StringBuffer();
								 stringBuffer.append("<Service_Information>");
								 stringBuffer.append("<RESULT>");
								 stringBuffer.append(retCode);
								 stringBuffer.append("</RESULT>");
								 stringBuffer.append("<RESULT_INFO>");
								 stringBuffer.append(resultInfoStr);
								 stringBuffer.append("</RESULT_INFO>");
								 stringBuffer.append("<STOP_STATE>");
								 stringBuffer.append(stopStateStr);
								 stringBuffer.append("</STOP_STATE>");
								 stringBuffer.append("<OPER_DATE>");
								 stringBuffer.append(operDateStr);
								 stringBuffer.append("</OPER_DATE>");
								 stringBuffer.append("</Service_Information>");
							 }
							 
							
						} catch (Exception e) {
							logger.warn("response  is valid.", e);
						}
				}
				//记录到BUSNIESS_RECORD_PORT表
				LogBusniessRecordPort(reqXmlMessage, retCode, errMes);
			    logger.info("下游响应的消息"+resp);
				//输出下游返回的信息
				writeOutResponseMessage(receiveTime, body, reqXmlMessage, stringBuffer);
			}
			///////电子发票查询QueryNetInvoice.HB//////////////////////////////////////////
			else if (reqXmlMessage.getSCID().equals("QueryNetInvoice.HB@027.ctnbc-bon.net")) {
					logger.info("======QueryNetInvoice.HB.getDATA()======"+ reqXmlMessage.getDATA());
					Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
					String regionId = (String) map.get("REGION_ID");
					logger.info("==============regionId========" + regionId);
					String acctId = (String) map.get("ACCT_ID");
					logger.info("==============acctId========" + acctId);
					String salesIndentId = (String) map.get("SALES_INDENT_ID");
					logger.info("==============salesIndentId========" + salesIndentId);
					String acctMonth = (String) map.get("ACCT_MONTH");
					logger.info("==============acctMonth========" + acctMonth);
					String invoiceType = (String) map.get("INVOICE_TYPE");
					logger.info("==============invoiceType========" + invoiceType);
					String areaCode = (String) map.get("AREA_CODE");
					logger.info("==============areaCode========" + areaCode);

					String url = null;
					 //1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
					int urlForJf3 = getURLForJf3(areaCode,IS_WH);
					switch (urlForJf3) {
					case 1://新武汉
						url = QueryNetInvoiceWHjf3;
						break;
					case 2://新湖北
						url = QueryNetInvoiceHBjf3;
						break;
					case 3://旧武汉
						url = QueryNetInvoiceWH;
						break;
					case 4://旧湖北
						url = QueryNetInvoiceHB;
						break;
						
					default:
						break;
					}
					logger.info("===============调用地址url============" + url);
					Element serviceInformation = DocumentHelper.createElement("Service_Information");
					try {
						if(urlForJf3 == 1 || urlForJf3 == 2) {
							logger.info("==============进入新接口======urlForJf3:"+urlForJf3 );
							BillingBossServiceImplServiceSoapBindingStub stu  = new BillingBossServiceImplServiceSoapBindingStub(new java.net.URL(url),null);
							com.asiainfo.webservice.QueryNetInvoiceRequest param = new com.asiainfo.webservice.QueryNetInvoiceRequest();
							param.setACCT_ID(acctId);
							param.setREGION_ID(regionId);
							param.setACCT_MONTH(acctMonth);
							param.setSALES_INDENT_ID(salesIndentId);
							param.setINVOICE_TYPE(invoiceType);
							com.asiainfo.webservice.QueryNetInvoiceResponse resp = stu.queryNetInvoice(param);
							int result =resp.getRESULT();
							logger.info("==============after========result:"+result );
							if(result==0){
                                logger.info("============new Gson():"+new Gson().toJson(resp));
								 com.asiainfo.webservice.QueryNetInvoiceResponseItem[] oweItem = resp.getITEM();
								 QueryNetInvoiceResponseItemExt[] oweItems = resp.getITEM_EXT();
								logger.info("==============666666666========");
								StringBuffer returnBuffer = new StringBuffer();
								StringBuffer returnItmeBuffer = null;
								returnBuffer.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
								returnBuffer.append("<soapenv:Body>");
								returnBuffer.append("<QueryNetInvoiceResponse xmlns=\"http://webservice.asiainfo.com/\">");
								returnBuffer.append("<RESULT>0</RESULT>");
								int arrayLenth = oweItem.length;
								if(oweItem != null) {
									if(oweItems != null) {
										arrayLenth = oweItem.length > oweItems.length ? oweItem.length: oweItems.length;
									}
								}
								String inId = "";
								String orderNo = "";
								for (int i = 0; i < arrayLenth; i++) {
									
									logger.info("==============iiiiii========"+i);
									logger.info("==============77777========");
									logger.info("==============oweItem========"+oweItem.toString());
									logger.info("==============oweItems========"+oweItems);
									returnItmeBuffer = new StringBuffer();
									if(oweItem.length-1>=i) {
										returnItmeBuffer.append("<ITEM>");
										com.asiainfo.webservice.QueryNetInvoiceResponseItem o=oweItem[i];
										String aId = StringUtils.isEmpty(o.getACCT_ID()) ? "" : o.getACCT_ID();
										returnItmeBuffer.append("<ACCT_ID>"+aId+"</ACCT_ID>");
										String aName = StringUtils.isEmpty(o.getACCT_NAME()) ? "" : o.getACCT_NAME();
										returnItmeBuffer.append("<ACCT_NAME>"+aName+"</ACCT_NAME>");
										String inType = StringUtils.isEmpty(o.getINVOICE_TYPE()) ? "" : o.getINVOICE_TYPE();
										returnItmeBuffer.append("<INVOICE_TYPE>"+inType+"</INVOICE_TYPE>");
										String amount = StringUtils.isEmpty(o.getAMOUNT()) ? "" : o.getAMOUNT();
										returnItmeBuffer.append("<AMOUNT>"+amount+"</AMOUNT>");
										String state = StringUtils.isEmpty(o.getSTATE()) ? "" : o.getSTATE();
										returnItmeBuffer.append("<STATE>"+state+"</STATE>");
										String payState = StringUtils.isEmpty(o.getPAY_STATE()) ? "" : o.getPAY_STATE();
										returnItmeBuffer.append("<PAY_STATE>"+payState+"</PAY_STATE>");
										String inAddr = StringUtils.isEmpty(o.getINVOICE_ADDR()) ? "" : o.getINVOICE_ADDR();
										returnItmeBuffer.append("<INVOICE_ADDR>"+inAddr+"</INVOICE_ADDR>");
										String aMonth = StringUtils.isEmpty(o.getACCT_MONTH()) ? "" : o.getACCT_MONTH();
										returnItmeBuffer.append("<ACCT_MONTH>"+aMonth+"</ACCT_MONTH>");
										String inDate = StringUtils.isEmpty(o.getINVOKE_DATE()) ? "" : o.getINVOKE_DATE();
										returnItmeBuffer.append("<INVOKE_DATE>"+inDate+"</INVOKE_DATE>");
										inId = StringUtils.isEmpty( o.getINVOICE_ID()) ? "" : o.getINVOICE_ID();
										returnItmeBuffer.append("<INVOICE_ID>"+inId+"</INVOICE_ID>");
										orderNo = StringUtils.isEmpty(o.getORDER_NO() ) ? "" : o.getORDER_NO();
										returnItmeBuffer.append("<ORDER_NO>"+orderNo+"</ORDER_NO>");
										String accNbr = StringUtils.isEmpty(o.getACC_NBR()) ? "" : o.getACC_NBR();
										returnItmeBuffer.append("<ACC_NBR>"+accNbr+"</ACC_NBR>");
										String smsNbr = StringUtils.isEmpty(o.getSMS_NBR() ) ? "" : o.getSMS_NBR();
										returnItmeBuffer.append("<SMS_NBR>"+smsNbr+"</SMS_NBR>");
										String email = StringUtils.isEmpty(o.getEMAIL() ) ? "" : o.getEMAIL();
										returnItmeBuffer.append("<EMAIL>"+email+"</EMAIL>");
										String remark = StringUtils.isEmpty(o.getREMARK()) ? "" : o.getREMARK();
										returnItmeBuffer.append("<REMARK>"+remark+"</REMARK>");
										String errorInfo = StringUtils.isEmpty(o.getERROR_INFO() ) ? "" : o.getERROR_INFO();
										returnItmeBuffer.append("<ERROR_INFO>"+errorInfo+"</ERROR_INFO>");
										returnItmeBuffer.append("</ITEM>");
									}
									if(oweItems != null) {
										if(oweItems.length-1>=i) {
											QueryNetInvoiceResponseItemExt q=oweItems[i];
											String inIds = StringUtils.isEmpty(q.getINVOICE_ID()) ? "" : q.getINVOICE_ID();
											String oId = StringUtils.isEmpty(q.getORDER_NO()) ? "" : q.getORDER_NO();
											returnItmeBuffer.append("<ITEM_EXT>");
											returnItmeBuffer.append("<INVOICE_ID>"+inIds+"</INVOICE_ID>");
											returnItmeBuffer.append("<ORDER_NO>"+oId+"</ORDER_NO>");
											String FPDM = (q.getFPDM() == null || q.getFPDM().equals("")) ? "" : q.getFPDM();
											logger.info("==============FPDM========" + FPDM);
											returnItmeBuffer.append("<FPDM>"+FPDM+"</FPDM>");
											String FPHM = (q.getFPHM() == null || q.getFPHM().equals("")) ? "" : q.getFPHM();
											logger.info("==============FPHM========" + FPHM);
											returnItmeBuffer.append("<FPHM>"+FPHM+"</FPHM>");
											String JYM = (q.getJYM() == null || q.getJYM().equals("")) ? "" : q.getJYM();
											logger.info("==============JYM========" + JYM);
											returnItmeBuffer.append("<JYM>"+JYM+"</JYM>");
											String FPLS = (q.getFPLS() == null || q.getFPLS().equals("")) ? "" :q.getFPLS();
											logger.info("==============FPLS========" + FPLS);
											returnItmeBuffer.append("<JYM>"+FPLS+"</JYM>");
											returnItmeBuffer.append("</ITEM_EXT>");
										}
									}
									returnBuffer.append(returnItmeBuffer.toString());
								}
								returnBuffer.append("</QueryNetInvoiceResponse>");
								returnBuffer.append("</soapenv:Body>");
								returnBuffer.append("</soapenv:Envelope>");
								logger.info("==============下游返回的消息6666========" + returnBuffer.toString());
								logger.info("==============oi.length========" + oweItem.length);
							
								Element element = serviceInformation.addElement("Result");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								
								for (int i = 0; i < oweItem.length; i++) {
									logger.info("=============进入for========"+i );
									OWE_ITEM = DocumentHelper.createElement("ITEM");
									Element oweItemE= OWE_ITEM.addElement("ACCT_ID");
									
									if (oweItem[i].getACCT_ID() == null|| oweItem[i].getACCT_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_NAME");
									if (oweItem[i].getACCT_NAME() == null|| oweItem[i].getACCT_NAME().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_NAME());
									}
									
									oweItemE = OWE_ITEM.addElement("INVOICE_ADDR_EXT");
									if (oweItem[i].getINVOICE_ADDR_EXT() == null|| oweItem[i].getINVOICE_ADDR_EXT().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ADDR_EXT());
									}
									
									oweItemE = OWE_ITEM.addElement("INVOICE_TYPE");
									if (oweItem[i].getINVOICE_TYPE() == null|| oweItem[i].getINVOICE_TYPE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_TYPE());
									}
									
									oweItemE = OWE_ITEM.addElement("AMOUNT");
									if (oweItem[i].getAMOUNT() == null|| oweItem[i].getAMOUNT().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getAMOUNT());
									}
									
									oweItemE = OWE_ITEM.addElement("STATE");
									if (oweItem[i].getSTATE() == null|| oweItem[i].getSTATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSTATE());
									}
									
									oweItemE = OWE_ITEM.addElement("PAY_STATE");
									if (oweItem[i].getPAY_STATE() == null|| oweItem[i].getPAY_STATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getPAY_STATE());
									}
									
									oweItemE = OWE_ITEM.addElement("INVOICE_ADDR");
									if (oweItem[i].getINVOICE_ADDR() == null|| oweItem[i].getINVOICE_ADDR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ADDR());
									}
									
									oweItemE = OWE_ITEM.addElement("INVOICE_ID");
									if (oweItem[i].getINVOICE_ID() == null|| oweItem[i].getINVOICE_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ID());
									}
									
									oweItemE = OWE_ITEM.addElement("ORDER_NO");
									if (oweItem[i].getORDER_NO() == null|| oweItem[i].getORDER_NO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getORDER_NO());
									}
									
									oweItemE = OWE_ITEM.addElement("ACC_NBR");
									if (oweItem[i].getACC_NBR() == null|| oweItem[i].getACC_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACC_NBR());
									}
									
									oweItemE = OWE_ITEM.addElement("SMS_NBR");
									if (oweItem[i].getSMS_NBR() == null|| oweItem[i].getSMS_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSMS_NBR());
									}
									
									oweItemE = OWE_ITEM.addElement("EMAIL");
									if (oweItem[i].getEMAIL() == null|| oweItem[i].getEMAIL().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getEMAIL());
									}
									
									oweItemE = OWE_ITEM.addElement("ERROR_INFO");
									if (oweItem[i].getERROR_INFO() == null|| oweItem[i].getERROR_INFO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getERROR_INFO());
									}
									
									oweItemE = OWE_ITEM.addElement("REMARK");
									if (oweItem[i].getREMARK() == null|| oweItem[i].getREMARK().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getREMARK());
									}
									
									oweItemE = OWE_ITEM.addElement("ACCT_MONTH");
									if (oweItem[i].getACCT_MONTH() == null|| oweItem[i].getACCT_MONTH().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_MONTH());
									}
									
									oweItemE = OWE_ITEM.addElement("INVOKE_DATE");
									if (oweItem[i].getINVOKE_DATE() == null|| oweItem[i].getINVOKE_DATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOKE_DATE());
									}
									
									serviceInformation.add(OWE_ITEM);
									logger.info("=============oweItemE========" +oweItemE.asXML());
									logger.info("=============serviceInformation========" +serviceInformation.asXML());
								}
								if(oweItems != null) {
									for (int i = 0; i < oweItems.length; i++) {
										String inIds = StringUtils.isEmpty(oweItems[i].getINVOICE_ID()) ? "" : oweItems[i].getINVOICE_ID();
										String oId = StringUtils.isEmpty(oweItems[i].getORDER_NO()) ? "" : oweItems[i].getORDER_NO();
										logger.info("=============inId========" +inIds);
										logger.info("=============oId========" +oId);
										OWE_ITEM_EXT = DocumentHelper.createElement("ITEM_EXT");
										Element oweItemEXT= OWE_ITEM_EXT.addElement("INVOICE_ID");
									    oweItemEXT.setText(inIds);
										oweItemEXT = OWE_ITEM_EXT.addElement("ORDER_NO");
										oweItemEXT.setText(oId);
										oweItemEXT = OWE_ITEM_EXT.addElement("FPDM");
										if (StringUtils.isEmpty(oweItems[i].getFPDM())) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPDM());
										}
										
										oweItemEXT = OWE_ITEM_EXT.addElement("FPHM");
										if (oweItems[i].getFPHM() == null|| oweItems[i].getFPHM().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPHM());
										}
										
										oweItemEXT = OWE_ITEM_EXT.addElement("JYM");
										if (oweItems[i].getJYM() == null|| oweItems[i].getJYM().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getJYM());
										}
										
										oweItemEXT = OWE_ITEM_EXT.addElement("FPLS");
										if (oweItems[i].getFPLS() == null|| oweItems[i].getFPLS().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPLS());
										}
										serviceInformation.add(OWE_ITEM_EXT);
										logger.info("=============OWE_ITEM_EXT========" +oweItemEXT.asXML());
										logger.info("=============serviceInformation========" +serviceInformation.asXML());
									}
								}
								
									
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
							}else if(result==1){
								logger.info("==============result========" + result);
								Element element = serviceInformation.addElement("Result");
								element.setText("1");
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));
								
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(-1);
								TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								tmallLogDao1.insertBusinessRecordPort(bean);	
							}
						}else {
							logger.info("==============进入老接口======urlForJf3:"+urlForJf3 );
							BossServicePortTypeYGZProxy proxy = new BossServicePortTypeYGZProxy(url);
							QueryNetInvoiceRequest queryNetInvoiceRequest = new QueryNetInvoiceRequest();
							queryNetInvoiceRequest.setACCT_ID(acctId);
							queryNetInvoiceRequest.setREGION_ID(regionId);
							queryNetInvoiceRequest.setACCT_MONTH(acctMonth);
							queryNetInvoiceRequest.setSALES_INDENT_ID(salesIndentId);
							queryNetInvoiceRequest.setINVOICE_TYPE(invoiceType);
							QueryNetInvoiceResponse resp = proxy.queryNetInvoice(queryNetInvoiceRequest);
							int result = resp.getRESULT();
							if(resp.getRESULT()==0){
								QueryNetInvoiceResponseItem[] oweItem = resp.getITEM();
								QueryNetInvoiceResponseItem[] oweItems = resp.getITEM_EXT();
								logger.info("==============666666666========");
								StringBuffer returnBuffer = new StringBuffer();
								StringBuffer returnItmeBuffer = null;
								returnBuffer.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
								returnBuffer.append("<soapenv:Body>");
								returnBuffer.append("<QueryNetInvoiceResponse xmlns=\"http://ygz.service.boss/client/\">");
								returnBuffer.append("<RESULT>0</RESULT>");
								int arrayLenth = oweItem.length;
								if(oweItem != null) {
									if(oweItems != null) {
										arrayLenth = oweItem.length > oweItems.length ? oweItem.length: oweItems.length;
									}

								}
								String inId = "";
								String orderNo = "";
								for (int i = 0; i < arrayLenth; i++) {

									logger.info("==============iiiiii========"+i);
									logger.info("==============77777========");
									logger.info("==============oweItem========"+oweItem.toString());
									logger.info("==============oweItems========"+oweItems);
									returnItmeBuffer = new StringBuffer();
									if(oweItem.length-1>=i) {
										returnItmeBuffer.append("<ITEM>");
										QueryNetInvoiceResponseItem o=oweItem[i];
										String aId = StringUtils.isEmpty(o.getACCT_ID()) ? "" : o.getACCT_ID();
										returnItmeBuffer.append("<ACCT_ID>"+aId+"</ACCT_ID>");
										String aName = StringUtils.isEmpty(o.getACCT_NAME()) ? "" : o.getACCT_NAME();
										returnItmeBuffer.append("<ACCT_NAME>"+aName+"</ACCT_NAME>");
										String inType = StringUtils.isEmpty(o.getINVOICE_TYPE()) ? "" : o.getINVOICE_TYPE();
										returnItmeBuffer.append("<INVOICE_TYPE>"+inType+"</INVOICE_TYPE>");
										String amount = StringUtils.isEmpty(o.getAMOUNT()) ? "" : o.getAMOUNT();
										returnItmeBuffer.append("<AMOUNT>"+amount+"</AMOUNT>");
										String state = StringUtils.isEmpty(o.getSTATE()) ? "" : o.getSTATE();
										returnItmeBuffer.append("<STATE>"+state+"</STATE>");
										String payState = StringUtils.isEmpty(o.getPAY_STATE()) ? "" : o.getPAY_STATE();
										returnItmeBuffer.append("<PAY_STATE>"+payState+"</PAY_STATE>");
										String inAddr = StringUtils.isEmpty(o.getINVOICE_ADDR()) ? "" : o.getINVOICE_ADDR();
										returnItmeBuffer.append("<INVOICE_ADDR>"+inAddr+"</INVOICE_ADDR>");
										String aMonth = StringUtils.isEmpty(o.getACCT_MONTH()) ? "" : o.getACCT_MONTH();
										returnItmeBuffer.append("<ACCT_MONTH>"+aMonth+"</ACCT_MONTH>");
										String inDate = StringUtils.isEmpty(o.getINVOKE_DATE()) ? "" : o.getINVOKE_DATE();
										returnItmeBuffer.append("<INVOKE_DATE>"+inDate+"</INVOKE_DATE>");
										inId = StringUtils.isEmpty( o.getINVOICE_ID()) ? "" : o.getINVOICE_ID();
										returnItmeBuffer.append("<INVOICE_ID>"+inId+"</INVOICE_ID>");
										orderNo = StringUtils.isEmpty(o.getORDER_NO() ) ? "" : o.getORDER_NO();
										returnItmeBuffer.append("<ORDER_NO>"+orderNo+"</ORDER_NO>");
										String accNbr = StringUtils.isEmpty(o.getACC_NBR()) ? "" : o.getACC_NBR();
										returnItmeBuffer.append("<ACC_NBR>"+accNbr+"</ACC_NBR>");
										String smsNbr = StringUtils.isEmpty(o.getSMS_NBR() ) ? "" : o.getSMS_NBR();
										returnItmeBuffer.append("<SMS_NBR>"+smsNbr+"</SMS_NBR>");
										String email = StringUtils.isEmpty(o.getEMAIL() ) ? "" : o.getEMAIL();
										returnItmeBuffer.append("<EMAIL>"+email+"</EMAIL>");
										String remark = StringUtils.isEmpty(o.getREMARK()) ? "" : o.getREMARK();
										returnItmeBuffer.append("<REMARK>"+remark+"</REMARK>");
										String errorInfo = StringUtils.isEmpty(o.getERROR_INFO() ) ? "" : o.getERROR_INFO();
										returnItmeBuffer.append("<ERROR_INFO>"+errorInfo+"</ERROR_INFO>");
										returnItmeBuffer.append("</ITEM>");
									}
									if(oweItems != null) {
										if(oweItems.length-1>=i) {
											QueryNetInvoiceResponseItem q=oweItems[i];
											String inIds = StringUtils.isEmpty(q.getINVOICE_ID()) ? "" : q.getINVOICE_ID();
											String oId = StringUtils.isEmpty(q.getORDER_NO()) ? "" : q.getORDER_NO();
											returnItmeBuffer.append("<ITEM_EXT>");
											returnItmeBuffer.append("<INVOICE_ID>"+inIds+"</INVOICE_ID>");
											returnItmeBuffer.append("<ORDER_NO>"+oId+"</ORDER_NO>");
											String FPDM = (q.getFPDM() == null || q.getFPDM().equals("")) ? "" : q.getFPDM();
											logger.info("==============FPDM========" + FPDM);
											returnItmeBuffer.append("<FPDM>"+FPDM+"</FPDM>");
											String FPHM = (q.getFPHM() == null || q.getFPHM().equals("")) ? "" : q.getFPHM();
											logger.info("==============FPHM========" + FPHM);
											returnItmeBuffer.append("<FPHM>"+FPHM+"</FPHM>");
											String JYM = (q.getJYM() == null || q.getJYM().equals("")) ? "" : q.getJYM();
											logger.info("==============JYM========" + JYM);
											returnItmeBuffer.append("<JYM>"+JYM+"</JYM>");
											String FPLS = (q.getFPLS() == null || q.getFPLS().equals("")) ? "" :q.getFPLS();
											logger.info("==============FPLS========" + FPLS);
											returnItmeBuffer.append("<JYM>"+FPLS+"</JYM>");
											returnItmeBuffer.append("</ITEM_EXT>");
										}
									}
									returnBuffer.append(returnItmeBuffer.toString());
								}
								returnBuffer.append("</QueryNetInvoiceResponse>");
								returnBuffer.append("</soapenv:Body>");
								returnBuffer.append("</soapenv:Envelope>");
								logger.info("==============下游返回的消息6666========" + returnBuffer.toString());
								logger.info("==============oi.length========" + oweItem.length);

								Element element = serviceInformation.addElement("Result");
								element.setText(String.valueOf(result));
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));

								for (int i = 0; i < oweItem.length; i++) {
									logger.info("=============进入for========"+i );
									OWE_ITEM = DocumentHelper.createElement("ITEM");
									Element oweItemE= OWE_ITEM.addElement("ACCT_ID");

									if (oweItem[i].getACCT_ID() == null|| oweItem[i].getACCT_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_ID());
									}

									oweItemE = OWE_ITEM.addElement("ACCT_NAME");
									if (oweItem[i].getACCT_NAME() == null|| oweItem[i].getACCT_NAME().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_NAME());
									}

									oweItemE = OWE_ITEM.addElement("INVOICE_ADDR_EXT");
									if (oweItem[i].getINVOICE_ADDR_EXT() == null|| oweItem[i].getINVOICE_ADDR_EXT().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ADDR_EXT());
									}

									oweItemE = OWE_ITEM.addElement("INVOICE_TYPE");
									if (oweItem[i].getINVOICE_TYPE() == null|| oweItem[i].getINVOICE_TYPE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_TYPE());
									}

									oweItemE = OWE_ITEM.addElement("AMOUNT");
									if (oweItem[i].getAMOUNT() == null|| oweItem[i].getAMOUNT().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getAMOUNT());
									}

									oweItemE = OWE_ITEM.addElement("STATE");
									if (oweItem[i].getSTATE() == null|| oweItem[i].getSTATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSTATE());
									}

									oweItemE = OWE_ITEM.addElement("PAY_STATE");
									if (oweItem[i].getPAY_STATE() == null|| oweItem[i].getPAY_STATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getPAY_STATE());
									}

									oweItemE = OWE_ITEM.addElement("INVOICE_ADDR");
									if (oweItem[i].getINVOICE_ADDR() == null|| oweItem[i].getINVOICE_ADDR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ADDR());
									}

									oweItemE = OWE_ITEM.addElement("INVOICE_ID");
									if (oweItem[i].getINVOICE_ID() == null|| oweItem[i].getINVOICE_ID().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOICE_ID());
									}

									oweItemE = OWE_ITEM.addElement("ORDER_NO");
									if (oweItem[i].getORDER_NO() == null|| oweItem[i].getORDER_NO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getORDER_NO());
									}

									oweItemE = OWE_ITEM.addElement("ACC_NBR");
									if (oweItem[i].getACC_NBR() == null|| oweItem[i].getACC_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACC_NBR());
									}

									oweItemE = OWE_ITEM.addElement("SMS_NBR");
									if (oweItem[i].getSMS_NBR() == null|| oweItem[i].getSMS_NBR().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getSMS_NBR());
									}

									oweItemE = OWE_ITEM.addElement("EMAIL");
									if (oweItem[i].getEMAIL() == null|| oweItem[i].getEMAIL().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getEMAIL());
									}

									oweItemE = OWE_ITEM.addElement("ERROR_INFO");
									if (oweItem[i].getERROR_INFO() == null|| oweItem[i].getERROR_INFO().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getERROR_INFO());
									}

									oweItemE = OWE_ITEM.addElement("REMARK");
									if (oweItem[i].getREMARK() == null|| oweItem[i].getREMARK().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getREMARK());
									}

									oweItemE = OWE_ITEM.addElement("ACCT_MONTH");
									if (oweItem[i].getACCT_MONTH() == null|| oweItem[i].getACCT_MONTH().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getACCT_MONTH());
									}

									oweItemE = OWE_ITEM.addElement("INVOKE_DATE");
									if (oweItem[i].getINVOKE_DATE() == null|| oweItem[i].getINVOKE_DATE().equals("")) {
										oweItemE.setText("	");
									} else {
										oweItemE.setText(oweItem[i].getINVOKE_DATE());
									}

									serviceInformation.add(OWE_ITEM);
									logger.info("=============oweItemE========" +oweItemE.asXML());
									logger.info("=============serviceInformation========" +serviceInformation.asXML());
								}
								if(oweItems != null) {
									for (int i = 0; i < oweItems.length; i++) {
										String inIds = (oweItems[i].getINVOICE_ID() == null|| oweItems[i].getINVOICE_ID().equals("")) ? "" : oweItems[i].getINVOICE_ID();
										String oId = (oweItems[i].getORDER_NO() == null|| oweItems[i].getORDER_NO().equals("")) ? "" : oweItems[i].getORDER_NO();
										logger.info("=============inId========" +inIds);
										logger.info("=============oId========" +oId);
										OWE_ITEM_EXT = DocumentHelper.createElement("ITEM_EXT");
										Element oweItemEXT= OWE_ITEM_EXT.addElement("INVOICE_ID");
									    oweItemEXT.setText(inIds);
										oweItemEXT = OWE_ITEM_EXT.addElement("ORDER_NO");
										oweItemEXT.setText(oId);
										oweItemEXT = OWE_ITEM_EXT.addElement("FPDM");
										if (oweItems[i].getFPDM() == null|| oweItems[i].getFPDM().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPDM());
										}

										oweItemEXT = OWE_ITEM_EXT.addElement("FPHM");
										if (oweItems[i].getFPHM() == null|| oweItems[i].getFPHM().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPHM());
										}

										oweItemEXT = OWE_ITEM_EXT.addElement("JYM");
										if (oweItems[i].getJYM() == null|| oweItems[i].getJYM().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getJYM());
										}

										oweItemEXT = OWE_ITEM_EXT.addElement("FPLS");
										if (oweItems[i].getFPLS() == null|| oweItems[i].getFPLS().equals("")) {
											oweItemEXT.setText("	");
										} else {
											oweItemEXT.setText(oweItems[i].getFPLS());
										}
										serviceInformation.add(OWE_ITEM_EXT);
										logger.info("=============OWE_ITEM_EXT========" +oweItemEXT.asXML());
										logger.info("=============serviceInformation========" +serviceInformation.asXML());
									}
								}


								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");

								tmallLogDao.insertBusinessRecordPort(bean);
							}else if(result==1){
								logger.info("==============result========" + result);
								Element element = serviceInformation.addElement("Result");
								element.setText("1");
								element = serviceInformation.addElement("RESULT");
								element.setText(String.valueOf(result));

								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(-1);
								TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");
								tmallLogDao1.insertBusinessRecordPort(bean);

							}
						}
					} catch (Exception e) {
						logger.error("Exception:",e);
					}
					
					
					XmlMessage ack = new XmlMessage(true);
					ack.setMID(reqXmlMessage.getMID());
					ack.setREPTAG(0);
					ack.setRTT(String.valueOf(receiveTime));
					ack.setSIG(null);
					ack.setRC("0");
					ack.setDS("SUCCESS");
					ack.setDATA(serviceInformation.asXML());
					String respXML = convertResponseString(ack);
					logger.info("=======================respXML========================");
					logger.info(respXML);
					logger.info("=======================respXML========================");
					byte[] resps = respXML.getBytes("UTF-8");
					ack.setLength(resps.length);
					ack.setMsgTime(System.currentTimeMillis());
					logger.info("=============8888888========");
					body.write(resps);
					body.close();

				}
				
				//////////////////////////////////////////////////////////////////
					else if ((reqXmlMessage.getSCID().equals("Recharge.BestPay@027.ctnbc-bon.net"))) {
						logger.info("======Recharge.BestPay.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());

						//从数据库取key
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");
						TInterfacePassword tInterfacePassword = tmallLogDao.getTInterfacePassword();
					
						
						String responseCode =	getTranRecharge(
								tInterfacePassword.getKeyValue(),
								tyConfigService.getValue("TranRechargeUrl", ""),
								map, reqXmlMessage, body, receiveTime);
						logger.info("responseCoderesponseCode"+responseCode);
						if((map.containsKey("Area_Code")&&"000000".equals(responseCode))){
							logger.info("responseCode121321"+responseCode);
							Element serviceInformation = DocumentHelper.createElement("Service_Information");
							Element element = serviceInformation.addElement("Area_Code");
							element.setText(map.get("Area_Code").toString());
							element = serviceInformation.addElement("Acc_Nbr");
							element.setText(map.get("ACCOUNTID").toString());
							element = serviceInformation.addElement("Block_Date");
							element.setText(map.get("ACCEPTTIME").toString());
							element = serviceInformation.addElement("Staff_Id");
							element.setText(map.get("Staff_Id").toString());
							element = serviceInformation.addElement("Balance_Amount");
							element.setText(map.get("TXNAMOUNT").toString());
							element = serviceInformation.addElement("Reverse_Amount");
							element.setText(map.get("RECHARGEAMT").toString());
							element = serviceInformation.addElement("Channel_Id");
							element.setText(map.get("Channel_Id").toString());
							element = serviceInformation.addElement("Site_Id");
							element.setText(map.get("Site_Id").toString());
							element = serviceInformation.addElement("Oper_Type");
							element.setText("1");
							element = serviceInformation.addElement("Oper_Serial_Nbr");
							element.setText(map.get("ACCEPTSEQNO").toString());
							element = serviceInformation.addElement("Oper_serial");
							XmlMessage req = new XmlMessage(true);
							WingBalanceQuery wingBalanceQuery = new WingBalanceQuery("", "", "", "", "", "", "");
							
							req.setIp(IP);
							req.setMsgTime(receiveTime);
							req.setMID(reqXmlMessage.getMID());
							req.setUID(reqXmlMessage.getUID());
							if(map.get("Area_Code").toString().equals("027")){
								req.setSCID("JfzsRechargeInfoSave.WH@027.ctnbc-bon.net");
							}else{
								req.setSCID("JfzsRechargeInfoSave.HB@027.ctnbc-bon.net");
							}
							req.setSIG(null);
							req.setREPTAG(0);
							req.setDATA(serviceInformation.asXML());
							req.setDataElement(serviceInformation);
						
							BusinessRecordPort bean= new BusinessRecordPort();
							bean.setSessionId(reqXmlMessage.getMID());
							bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
									.currentTimeMillis()));
							bean.setRequestHost(reqXmlMessage.getUID());
							bean.setServiceContextId(reqXmlMessage.getSCID());
							bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
									.currentTimeMillis()));
							bean.setResult(0);
							
							TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
							
							tmallLogDao1.insertBusinessRecordPort(bean);
						// new CallParam对象
						RechargeHandle rechargeHandle = new RechargeHandle(body,map,reqXmlMessage,IP,"","",wingBalanceQuery,tyConfigService.getValue("APP_CODE", ""),tyConfigService.getValue("IP", ""),tyConfigService.getValue("VERSION", ""),responseCode);
						CallParam callParam = new CallParam(req.getMID(), req.getSCID(),req, req.getUID(), rechargeHandle);
						BuzProcessorManager.getInstance().processRequest(callParam);
						}
					
						return;	

					} else if ((reqXmlMessage.getSCID().equals("RechargeQuery.BestPay@027.ctnbc-bon.net"))) {
						logger.info("======RechargeQuery.BestPay.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
						
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");
						TInterfacePassword tInterfacePassword = tmallLogDao.getTInterfacePassword();
						
						
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(0);
						TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
						tmallLogDao1.insertBusinessRecordPort(bean);
						
						
						getQueryRecharge(tInterfacePassword.getKeyValue(),tyConfigService.getValue("QueryRechargeUrl", ""), map,reqXmlMessage, body, receiveTime);
						return;
					} else if ((reqXmlMessage.getSCID().equals("RechargeRollback.BestPay@027.ctnbc-bon.net"))) {
						logger.info("======RechargeRollback.BestPay.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");
						TInterfacePassword tInterfacePassword = tmallLogDao.getTInterfacePassword();
						String responseCode =getRechargeRollback(tInterfacePassword.getKeyValue(),tyConfigService.getValue("RechargeRollbackUrl", ""), map,reqXmlMessage, body, receiveTime);
						if(responseCode.equals("000000")&&map.containsKey("Area_Code")){
							Element serviceInformation = DocumentHelper.createElement("Service_Information");
							Element element = serviceInformation.addElement("Area_Code");
							element.setText(map.get("Area_Code").toString());
							element = serviceInformation.addElement("Acc_Nbr");
							element.setText(map.get("ACCOUNTID").toString());
							element = serviceInformation.addElement("Block_Date");
							element.setText(map.get("ACCEPTTIME").toString());
							element = serviceInformation.addElement("Staff_Id");
							element.setText(map.get("Staff_Id").toString());
							element = serviceInformation.addElement("Balance_Amount");
							element.setText((Long.valueOf(map.get("TXNAMOUNT").toString())*-1)+"");
							element = serviceInformation.addElement("Reverse_Amount");
							element.setText((Long.valueOf(map.get("RECHARGEAMT").toString())*-1)+"");
							element = serviceInformation.addElement("Channel_Id");
							element.setText(map.get("Channel_Id").toString());
							element = serviceInformation.addElement("Site_Id");
							element.setText(map.get("Site_Id").toString());
							element = serviceInformation.addElement("Oper_Type");
							element.setText(map.get("Oper_Type").toString());
							element = serviceInformation.addElement("Oper_Serial_Nbr");
							element.setText(map.get("ACCEPTSEQNO").toString());
							element = serviceInformation.addElement("Oper_serial");
							element.setText(map.get("OLDACCEPTSEQNO").toString());
							XmlMessage req = new XmlMessage(true);
							req.setIp(IP);
							req.setMsgTime(receiveTime);
							req.setMID(reqXmlMessage.getMID());
							req.setUID(reqXmlMessage.getUID());
							if(map.get("Area_Code").toString().equals("027")){
								req.setSCID("JfzsRechargeInfoSave.WH@027.ctnbc-bon.net");
							}else{
								req.setSCID("JfzsRechargeInfoSave.HB@027.ctnbc-bon.net");
							}
							req.setSIG(null);
							req.setREPTAG(0);
							req.setDATA(serviceInformation.asXML());
							req.setDataElement(serviceInformation);
							WingBalanceQuery wingBalanceQuery = new WingBalanceQuery("", "", "", "", "", "", "");
						
							BusinessRecordPort bean= new BusinessRecordPort();
							bean.setSessionId(reqXmlMessage.getMID());
							bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
									.currentTimeMillis()));
							bean.setRequestHost(reqXmlMessage.getUID());
							bean.setServiceContextId(reqXmlMessage.getSCID());
							bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
									.currentTimeMillis()));
							bean.setResult(0);
							TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
							
							tmallLogDao1.insertBusinessRecordPort(bean);
							// new CallParam对象
						RechargeHandle rechargeHandle = new RechargeHandle(body,map,reqXmlMessage,IP,"","",wingBalanceQuery,tyConfigService.getValue("APP_CODE", ""),tyConfigService.getValue("IP", ""),tyConfigService.getValue("VERSION", ""),"");
						CallParam callParam = new CallParam(req.getMID(), req.getSCID(),req, req.getUID(), rechargeHandle);
						BuzProcessorManager.getInstance().processRequest(callParam);
						}
						return;
					} else if ((reqXmlMessage.getSCID().equals("BalanceQuery.BestPay@027.ctnbc-bon.net"))) {
					    //翼支付秘钥获取方式从数据库调整为取配置文件
						logger.info("======BalanceQuery.BestPay.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
//						TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");
//						TInterfacePassword tInterfacePassword = tmallLogDao.getTInterfacePassword();
                        String t_interface_password = userResourceConfigService.getValue("t_interface_password");

                        if(map.containsKey("Area_Code")){
								
							Element serviceInformation = DocumentHelper.createElement("Service_Information");
							
							Element element = serviceInformation.addElement("Area_Code");
							element.setText(map.get("Area_Code").toString());
							element = serviceInformation.addElement("Acc_Nbr");
							element.setText(map.get("ACCOUNTID").toString());
							element = serviceInformation.addElement("Query_Flag");
							element.setText("1");
								
							XmlMessage req = new XmlMessage(true);
							req.setIp(IP);
							req.setMsgTime(receiveTime);
							req.setMID(reqXmlMessage.getMID());
							req.setUID(reqXmlMessage.getUID());
							if(map.get("Area_Code").toString().equals("027")){
								req.setSCID("ServAttributeOwe.WH@027.ctnbc-bon.net");
							}else{
								req.setSCID("ServAttributeOwe.HB@027.ctnbc-bon.net");
							}
								req.setSIG(null);
								req.setREPTAG(0);
								req.setDATA(serviceInformation.asXML());
								req.setDataElement(serviceInformation);
								
								String accountidtype = (String) map.get("ACCOUNTIDTYPE");
								String accountid = (String) map.get("ACCOUNTID");
								String querytype = (String) map.get("QUERYTYPE");
								String acceptorgcode = (String) map.get("ACCEPTORGCODE");
								
								String acceptchannel = "";
								if (map.get("ACCEPTCHANNEL") != null
										&& !"".equals(map.get("ACCEPTCHANNEL"))) {
									acceptchannel = map.get("ACCEPTCHANNEL").toString();
								}
								String acceptseqno = (String) map.get("ACCEPTSEQNO");
								String accepttime = "";
								if (map.get("ACCEPTTIME") != null
										&& !"".equals(map.get("ACCEPTTIME"))) {
									accepttime = map.get("ACCEPTTIME").toString();
								}

								WingBalanceQuery wingBalanceQuery = new WingBalanceQuery(
										accountidtype, accountid, "1",
										acceptchannel, acceptseqno, accepttime,acceptorgcode);


                            RechargeHandle rechargeHandle = new RechargeHandle(body,map,reqXmlMessage,IP,t_interface_password,tyConfigService.getValue("QueryRechargeUrl", ""),wingBalanceQuery,tyConfigService.getValue("APP_CODE", ""),tyConfigService.getValue("IP", ""),tyConfigService.getValue("VERSION", ""),"");
								CallParam callParam = new CallParam(req.getMID(), req.getSCID(),req, req.getUID(), rechargeHandle);
								BuzProcessorManager.getInstance().processRequest(callParam);
								
							
								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(0);
								TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao1.insertBusinessRecordPort(bean);
								
						}else{
						String accountidtype = (String) map.get("ACCOUNTIDTYPE");
						String accountid = (String) map.get("ACCOUNTID");
						String querytype = (String) map.get("QUERYTYPE");
						String acceptorgcode = (String) map.get("ACCEPTORGCODE");
						
						String acceptchannel = "";
						if (map.get("ACCEPTCHANNEL") != null
								&& !"".equals(map.get("ACCEPTCHANNEL"))) {
							acceptchannel = map.get("ACCEPTCHANNEL").toString();
						}
						String acceptseqno = (String) map.get("ACCEPTSEQNO");
						String accepttime = "";
						if (map.get("ACCEPTTIME") != null
								&& !"".equals(map.get("ACCEPTTIME"))) {
							accepttime = map.get("ACCEPTTIME").toString();
						}

						WingBalanceQuery wingBalanceQuery = new WingBalanceQuery(
								accountidtype, accountid, querytype,
								acceptchannel, acceptseqno, accepttime,acceptorgcode);

						logger.info("accountidtype========" + accountidtype);
						logger.info("querytype========" + querytype);
						logger.info("acceptchannel========" + acceptchannel);
						logger.info("acceptseqno========" + acceptseqno);

						getBalanceQuery(t_interface_password,"", tyConfigService.getValue("QueryRechargeUrl", ""),wingBalanceQuery, reqXmlMessage, body,receiveTime);
						BusinessRecordPort bean= new BusinessRecordPort();
						bean.setSessionId(reqXmlMessage.getMID());
						bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
								.currentTimeMillis()));
						bean.setRequestHost(reqXmlMessage.getUID());
						bean.setServiceContextId(reqXmlMessage.getSCID());
						bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
								.currentTimeMillis()));
						bean.setResult(0);
						TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
						
						tmallLogDao1.insertBusinessRecordPort(bean);
						}
						return;
					}
			
					////////////////////////流量订购校验消息//////////////////////////////////
					 else if ((reqXmlMessage.getSCID().equals("FlowPacket.check@027.ctnbc-bon.net"))||(reqXmlMessage.getSCID().equals("FlowPacket.get@027.ctnbc-bon.net"))) {
							try {
								logger.info("======getDATA()======" + reqXmlMessage.getDATA());
								Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
								String transactionId = (String) map.get("transactionId");
								String busiTranId = (String) map.get("busiTranId");
								String appId = (String) map.get("appId");
								String channelId = (String) map.get("channelId");
								String signCode = (String) map.get("signCode");
								String capInstId = (String) map.get("capInstId");
								String encryptCode=null;
								if(map.containsKey("encryptCode")){
									 encryptCode = (String) map.get("encryptCode");
								}else{
									 encryptCode = "";
								}
								String rtnDataFormatType = (String) map.get("rtnDataFormatType");
								String contentId = (String) map.get("contentId");
								String regionId = (String) map.get("regionId");
								String staffId=null;
								if(map.containsKey("staffId")){
									 staffId = (String) map.get("staffId");
								}else{
									 staffId ="";
								}
								String staffCode = (String) map.get("staffCode");
								String accNbr = (String) map.get("accNbr");
								String pricePlanId = (String) map.get("pricePlanId");
								String actionType = (String) map.get("actionType");
								
								StringBuffer sb =new StringBuffer();
								sb.append("<interfaceRoot>");
								sb.append("<transactionId>" + transactionId + "</transactionId>");
								sb.append("<busiTranId>" + busiTranId + "</busiTranId>");
								sb.append("<appId>" + appId + "</appId>");
								sb.append("<channelId>" + channelId + "</channelId>");
								sb.append("<signCode>" + signCode + "</signCode>");
								sb.append("<capInstId>" + capInstId + "</capInstId>");
								sb.append("<encryptCode>" + encryptCode + "</encryptCode> ");
								sb.append("<rtnDataFormatType>" + rtnDataFormatType + "</rtnDataFormatType>");
								sb.append("<contentList>");
								if(reqXmlMessage.getSCID().equals("FlowPacket.check@027.ctnbc-bon.net")){
									logger.info("=====FlowPacket.check=====");
									sb.append("<content type='CHK_PRICE_ORDER'>");
								}if(reqXmlMessage.getSCID().equals("FlowPacket.get@027.ctnbc-bon.net")){
									logger.info("=====FlowPacket.get====");
									sb.append("<content type='SAVE_PRICE_ORDER'>");
								}
								sb.append("<contentId>" + contentId + "</contentId>");
								sb.append("<regionId>" + regionId + "</regionId>");
								sb.append("<staffId>" + staffId + "</staffId>");
								sb.append("<staffCode>" + staffCode + "</staffCode>");
								sb.append("<operInfo>");
								sb.append("<accNbr>" + accNbr+ "</accNbr>");
								sb.append("<pricePlanId>" + pricePlanId + "</pricePlanId>");
						     	sb.append("<actionType>" + actionType + "</actionType>");
								sb.append("</operInfo>");
								sb.append("</content></contentList></interfaceRoot>");
								
								String s ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+sb.toString();
								logger.info("请求报文:"+sb.toString());
								logger.info("请求地址:"+tmallFlow_url);
								String reslut = (String)getServiceClient(tmallFlow_url).invoke(new Object[] { s });// 调用后台webservice服务
								
								logger.info("returnXML:" + reslut);
								Map<String,Object> data =  new HashMap<String, Object>();
								if (reqXmlMessage.getSCID().equals("FlowPacket.check@027.ctnbc-bon.net")){
									data = xmlStrToMap(reslut);
									logger.info("下游返回报文:"+data.toString());
								}else if(reqXmlMessage.getSCID().equals("FlowPacket.get@027.ctnbc-bon.net")){
									data = xmlStrToMapForGet(reslut);
									logger.info("下游返回报文:"+data.toString());
								}
								
								
								Element Service_Information = DocumentHelper.createElement("Service_Information");
								Element element = Service_Information.addElement("Result");
							    element.setText(data.get("returnType").toString());
							    element = Service_Information.addElement("transactionId");
							    element.setText(data.get("transactionId").toString());
							    element = Service_Information.addElement("contentId");
							    element.setText(data.get("contentId").toString());
							    element = Service_Information.addElement("returnType");
							    element.setText(data.get("returnType").toString());
							    element = Service_Information.addElement("returnCode");
							    element.setText(data.get("returnCode").toString());
							    element = Service_Information.addElement("returnDesc");
							   
								if (data.get("returnDesc").toString() == null || data.get("returnDesc").toString().equals("")) {
									element.setText("	");
								} else {
									element.setText(data.get("returnDesc").toString());
								}
							    
							    element = Service_Information.addElement("returnMessage");
							    if (data.get("returnMessage").toString() == null || data.get("returnMessage").toString().equals("")) {
									element.setText("	");
								} else {
									element.setText(data.get("returnMessage").toString());
								}
							    
							    if(reqXmlMessage.getSCID().equals("FlowPacket.get@027.ctnbc-bon.net")&&data.get("returnType").toString().equals("0")){
							    	 element = Service_Information.addElement("SalesIndentId");
							    	 if (data.get("SalesIndentId").toString() == null || data.get("SalesIndentId").toString().equals("")) {
											element.setText("	");
										} else {
											element.setText(data.get("SalesIndentId").toString());
										}
									 element = Service_Information.addElement("CustIndentNbr");
									 
									 if (data.get("CustIndentNbr").toString() == null || data.get("CustIndentNbr").toString().equals("")) {
											element.setText("	");
										} else {
											element.setText(data.get("CustIndentNbr").toString());
										}
							    }
							   

								BusinessRecordPort bean= new BusinessRecordPort();
								bean.setSessionId(reqXmlMessage.getMID());
								bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
										.currentTimeMillis()));
								bean.setRequestHost(reqXmlMessage.getUID());
								bean.setServiceContextId(reqXmlMessage.getSCID());
								bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
										.currentTimeMillis()));
								bean.setResult(Integer.valueOf(data.get("returnType").toString()));
								TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
								
								tmallLogDao.insertBusinessRecordPort(bean);
								
								
							    XmlMessage ack = new XmlMessage(true);
								ack.setMID(reqXmlMessage.getMID());
								ack.setREPTAG(0);
								ack.setRTT(String.valueOf(receiveTime));
								ack.setSIG(null);
								ack.setRC("0");
								ack.setDS("SUCCESS");
								ack.setDATA(Service_Information.asXML());
								String respXML = convertResponseString(ack);
								logger.info("=======================respXML========================");
								logger.info(respXML);
								logger.info("=======================respXML========================");
								byte[] resps = respXML.getBytes("UTF-8");
								ack.setLength(resps.length);
								ack.setMsgTime(System.currentTimeMillis());
								body.write(resps);
								body.close();
								
								
							} catch (Exception e) {
								e.printStackTrace();
								logger.warn(e.getMessage());
							}
							
							return;
						}
					
					///////2.2.1	预存专款接口Prestore.HB@027.ctnbc-bon.net//////////////////////////////////////////
					else if (reqXmlMessage.getSCID().equals("Prestore.HB@027.ctnbc-bon.net")) {
						logger.info("======Prestore.HB.getDATA()======"+ reqXmlMessage.getDATA());
						Map<String, Object> map = xmlStrToMaps(reqXmlMessage.getDATA());
						String STAFF_ID = (String)map.get("STAFF_ID");			// 工号(必填)
						String SITE_ID = (String)map.get("SITE_ID");			// 营业厅编号(必填)
						String ACCT_NBR = (String)map.get("ACCT_NBR");			// 业务号码(必填)
						String BALANCE_TYPE_ID = (String)map.get("BALANCE_TYPE_ID");	// 专款类型编号(必填)
						String BALANCE = (String)map.get("BALANCE");			// 存款金额(分) (必填)
						String UPPER_AMOUNT = (String)map.get("UPPER_AMOUNT");	// 金额使用上限(分，缺省值默认9999元)
						String LOWER_AMOUNT = (String)map.get("LOWER_AMOUNT");	// 金额使用下限(分，缺省值默认0元)
						String CHANNEL_ID = (String)map.get("CHANNEL_ID");		// 渠道ID(缺省值默认5)
						String PAY_TYPE = (String)map.get("PAY_TYPE");			// 付费方式(缺省值默认500，现金)
						String EFF_Date = (String)map.get("EFF_Date");			// 生效日期yyyyMMdd(缺省值默认操作日期)
						String EXP_Date = (String)map.get("EXP_Date");			// 失效日期yyyyMMdd(缺省值默认20480101)
						String Area_Code = (String)map.get("Area_Code");		// 武电/非武电的标示
						if(StringUtils.isBlank(Area_Code)){
							Area_Code = "027";
						}
						String url = null;
						if (Area_Code.equals("027")) {
							url = PrestoreWH;
						} else {
							url = PrestoreHB;
						}
						logger.info("===============调用地址url============" + url);
						BossServicePortTypeYGZProxy proxy = new BossServicePortTypeYGZProxy(url);
						PrestoreSpecialFunRequest prestoreSpecialFunRequest = new PrestoreSpecialFunRequest();
						prestoreSpecialFunRequest.setSTAFF_ID(STAFF_ID);
						prestoreSpecialFunRequest.setSITE_ID(SITE_ID);
						prestoreSpecialFunRequest.setACCT_NBR(ACCT_NBR);
						prestoreSpecialFunRequest.setBALANCE_TYPE_ID(BALANCE_TYPE_ID);
						prestoreSpecialFunRequest.setBALANCE(BALANCE);
						prestoreSpecialFunRequest.setUPPER_AMOUNT(StringUtils.isBlank(UPPER_AMOUNT) ? "999900" : UPPER_AMOUNT);
						prestoreSpecialFunRequest.setLOWER_AMOUNT(StringUtils.isBlank(LOWER_AMOUNT) ? "0" : LOWER_AMOUNT);
						prestoreSpecialFunRequest.setCHANNEL_ID(StringUtils.isBlank(CHANNEL_ID) ? "5" : CHANNEL_ID);
						prestoreSpecialFunRequest.setPAY_TYPE(StringUtils.isBlank(PAY_TYPE) ? "500" : PAY_TYPE);
						prestoreSpecialFunRequest.setEFF_Date(StringUtils.isBlank(EFF_Date) ? new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()) : EFF_Date);
						prestoreSpecialFunRequest.setEXP_Date(StringUtils.isBlank(EXP_Date) ? "20480101" : EXP_Date);
						PrestoreSpecialFunResponse resp = null;
						
						try {
							resp = proxy.prestoreSpecialFun(prestoreSpecialFunRequest);
						} catch (Exception e) {
							logger.info("Exception:" + e.getMessage());
						}
						Element serviceInformation = DocumentHelper.createElement("Service_Information");
						if(resp != null){
							int result = resp.getRESULT();
							String resultInfo = resp.getRESULT_INFO();
							logger.info("下游webservice接口返回：<RESULT>" + result + "</RESULT><RESULT_INFO>" + resultInfo + "</RESULT_INFO>");
							Element element = serviceInformation.addElement("RESULT");
							element.setText(String.valueOf(result));
							element = serviceInformation.addElement("RESULT_INFO");
							element.setText(String.valueOf(resultInfo));

							BusinessRecordPort bean= new BusinessRecordPort();
							bean.setSessionId(reqXmlMessage.getMID());
							bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System.currentTimeMillis()));
							bean.setRequestHost(reqXmlMessage.getUID());
							bean.setServiceContextId(reqXmlMessage.getSCID());
							bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()));
							bean.setResult(result);
							TmallLogDao tmallLogDao = (TmallLogDao)SpringContext.getApplicationContext().getBean("tmallLogDao");	
							tmallLogDao.insertBusinessRecordPort(bean);
						}else{
							Element element = serviceInformation.addElement("RESULT");
							element.setText("-1");
							element = serviceInformation.addElement("RESULT_INFO");
							element.setText("系统异常，请重试！");
							logger.error("调用webservice接口失败：" + url);
						}
						XmlMessage ack = new XmlMessage(true);
						ack.setMID(reqXmlMessage.getMID());
						ack.setREPTAG(0);
						ack.setRTT(String.valueOf(receiveTime));
						ack.setSIG(null);
						ack.setRC("0");
						ack.setDS("SUCCESS");
						ack.setDATA(serviceInformation.asXML());
						String respXML = convertResponseString(ack);
						logger.info("=======================respXML========================");
						logger.info(respXML);
						logger.info("=======================respXML========================");
						byte[] resps = respXML.getBytes("UTF-8");
						ack.setLength(resps.length);
						ack.setMsgTime(System.currentTimeMillis());
						logger.info("=============8888888========");
						body.write(resps);
						body.close();
					}
				}
			} catch (Exception e) {
				logger.warn("parseWSRequest failed!!!");
				logger.warn("Exception:" + e.getMessage()+"MID:"+reqXmlMessage.getMID());
				directAck(createERRAnwser("", Constants.ResultCode.UNKNOW_MSG,e.toString()), body);
				return;
			}

		} catch (Exception e) {
			logger.warn("http request err:", e);
			if (body != null) {
				body.println("Server error :" + e.toString());
				body.close();
			}
		}
	}

	private void writeOutResponseMessage(long receiveTime, 
			                             PrintStream body,
			                             XmlMessage reqXmlMessage,
			                             StringBuffer stringBuffer)
			throws UnsupportedEncodingException, IOException 
	{
		XmlMessage ack = new XmlMessage(true);
		ack.setMID(reqXmlMessage.getMID());
		ack.setREPTAG(0);
		ack.setRTT(String.valueOf(receiveTime));
		ack.setSIG(null);
		ack.setRC("0");
		ack.setDS("SUCCESS");
		ack.setDATA(stringBuffer.toString());
		String respXML = convertResponseString(ack);
		logger.info(respXML);
		logger.info("=======================respXML========================");
		byte[] resps = respXML.getBytes("UTF-8");
		ack.setLength(resps.length);
		ack.setMsgTime(System.currentTimeMillis());
		body.write(resps);
		body.close();
	}

	private void LogBusniessRecordPort(XmlMessage reqXmlMessage, int retCode, String errMes) {
		BusinessRecordPort bean= new BusinessRecordPort();
		bean.setSessionId(reqXmlMessage.getMID());
		bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
		 		.currentTimeMillis()));
		bean.setRequestHost(reqXmlMessage.getUID());
		bean.setServiceContextId(reqXmlMessage.getSCID());
		bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
				.currentTimeMillis()));
		bean.setResult(retCode);
		bean.setResultReason(errMes);
		TmallLogDao tmallLogDao=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
		
		tmallLogDao.insertBusinessRecordPort(bean);
	}

	private StringBuffer getResponseMessage(StringBuffer para, PostMethod post)
			throws UnsupportedEncodingException, IOException, HttpException {
		 RequestEntity requestEntity = new StringRequestEntity(para.toString(), "text/xml", "UTF-8");
		 post.setRequestEntity(requestEntity);
		 HttpClient client = new HttpClient();
		 client.getHttpConnectionManager().getParams().setConnectionTimeout(5*1000);
		 client.executeMethod(post);
		 InputStream resStream = post.getResponseBodyAsStream();
		 BufferedReader br = new BufferedReader(new InputStreamReader(resStream));
		 StringBuffer resBuffer = new StringBuffer();  
		 String resTemp = "";
		 while((resTemp = br.readLine()) != null){  
		    resBuffer.append(resTemp);  
		 }
		return resBuffer;
	}

	private StringBuffer getSendWebServiceInfo(String regionId, 
			                                   String accNbr,
			                                   String blockState, 
			                                   String staffId)
	{
		 StringBuffer para = new StringBuffer();
		 para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cli=\"http://web.service.boss/client/\">");
		 para.append("<soapenv:Header/>");
		 para.append("<soapenv:Body>");
		 para.append("<cli:OutBlockUpRequest>");
		 para.append("<cli:regionId>" + regionId + "</cli:regionId>");
		 para.append("<cli:accNbr>" + accNbr + "</cli:accNbr>");
		 para.append("<cli:blockState>" + blockState + "</cli:blockState>");
		 para.append("<cli:staffId>" + staffId + "</cli:staffId>");
		 para.append("</cli:OutBlockUpRequest>");
		 para.append("</soapenv:Body>");
		 para.append("</soapenv:Envelope>");
		return para;
	}
	
	private StringBuffer getQueryStopWebServiceInfo(String accNbr,  String regionId)
    {
		StringBuffer para = new StringBuffer();
		para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cli=\"http://ygz.service.boss/client/\">");
		para.append("<soapenv:Header/>");
		para.append("<soapenv:Body>");
		para.append("<cli:QueryStopNetRequest>");
		para.append("<cli:REGION_ID>" + regionId + "</cli:REGION_ID>");
		para.append("<cli:ACC_NBR>" + accNbr + "</cli:ACC_NBR>");
		para.append("</cli:QueryStopNetRequest>");
		para.append("</soapenv:Body>");
		para.append("</soapenv:Envelope>");
		return para;
    }
	private StringBuffer getQueryStopWebServiceInfoNew(String accNbr, String regionId)
	{
		StringBuffer para = new StringBuffer();
		para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.asiainfo.com/\">\r\n" + 
				"   <soapenv:Header/>\r\n" + 
				"   <soapenv:Body>\r\n" + 
				"      <web:queryStopNet>\r\n" + 
				"         <QueryStopNetRequest>\r\n" + 
				"            <Region_Id>"+regionId+"</Region_Id>\r\n" + 
				"            <Acc_Nbr>"+accNbr+"</Acc_Nbr>\r\n" + 
				"         </QueryStopNetRequest>\r\n" + 
				"      </web:queryStopNet>\r\n" + 
				"   </soapenv:Body>\r\n" + 
				"</soapenv:Envelope>");
		return para;
	}
	private StringBuffer getQueryFluxCoverSendWebServiceInfo(String regionId, String accNbr)
    {
		StringBuffer para = new StringBuffer();
		para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cli=\"http://web.service.boss/client/\">");
		para.append("<soapenv:Header/>");
		para.append("<soapenv:Body>");
		para.append("<cli:QueryFluxCover>");
		para.append("<cli:REGION_ID>" + regionId + "</cli:REGION_ID>");
		para.append("<cli:ACC_NBR>" + accNbr + "</cli:ACC_NBR>");
		para.append("</cli:QueryFluxCover>");
		para.append("</soapenv:Body>");
		para.append("</soapenv:Envelope>");
		return para;
    }
	
	private StringBuffer getQueryFluxRecleanSendWebServiceInfo(String regionId, String accNbr, String accMonth)
    {
		StringBuffer para = new StringBuffer();
		para.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cli=\"http://web.service.boss/client/\">");
		para.append("<soapenv:Header/>");
		para.append("<soapenv:Body>");
		para.append("<cli:QueryFluxRecleanRequest>");
		para.append("<cli:REGION_ID>" + regionId + "</cli:REGION_ID>");
		para.append("<cli:ACC_NBR>" + accNbr + "</cli:ACC_NBR>");
		para.append("<cli:ACCT_MONTH>" + accMonth + "</cli:ACCT_MONTH>");
		para.append("</cli:QueryFluxRecleanRequest>");
		para.append("</soapenv:Body>");
		para.append("</soapenv:Envelope>");
		return para;
    }
	
	
	private static Call getServiceClient(String serverURL) throws Exception {
		Call call=null;
		try {
			Service service = new Service();
			call = (Call) service.createCall();						
			call.setTimeout(new Integer(30 * 1000));// 设置访问后台webservice服务的超时时间2秒,2秒后自动断开
			call.setTargetEndpointAddress(new URL(serverURL));// 设置webservice服务的url地址
			call.setOperationName(new QName("http://access.hbgz.com", "capacityService"));
		} catch (Exception e) {
			logger.info("异常"+e.getMessage());
		}
		return call;
	}
	
	public static String getIP(Request request) {
		try {

			// 先取一次request.getValue(“X-Real-IP"),
			// 如果有值就采用这个值，如果null，再取request.getClientAddress()
			String ip = request.getValue("X-Real-IP");// /132.129.24.34:64625
			// logger.debug("X-Real-IP:" + ip);
			if (ip == null || "".equals(ip)) {
				ip = request.getClientAddress() != null ? request
						.getClientAddress().getAddress().getHostAddress() : "";
			}
			return ip;
		} catch (Exception e) {
			logger.warn("get ip failed");
			return "";
		}
	}

	protected void dealWithOtherReqPath(long reqTime, Request request,
			PrintStream body, String reqPath) throws Exception {
		body.println("No service provided at this address path ");
		body.close();
	}

	public void setReplaceRealm(boolean replaceRealm) {
		this.replaceRealm = replaceRealm;
	}

	public void setStandardWSReqPath(String standardWSReqPath) {
		this.standardWSReqPath = standardWSReqPath;
	}

	public void setStandardHttpReqPath(String standardHttpReqPath) {
		this.standardHttpReqPath = standardHttpReqPath;
	}

	@Autowired
	public void setRsaSignService(RSASignService rsaSignService) {
		this.rsaSignService = rsaSignService;
	}

	@Override
	public Set<String> monitorConfKeys() {
		return monitorConfKeys;
	}

	@Override
	public void onConfigUpdated(String updatedKey) {
		this.loadParams();
	}

	private void loadParams() {
		maxLinkCount = confSrv.getIntValue(SysParamBean.KEY_BUSINESS_max_conn,
				10000);
		logger.info("load param " + SysParamBean.KEY_BUSINESS_max_conn
				+ " to value " + maxLinkCount);
	}

	@Override
	public int sendRequest(CallParam callParam) {// SGW soap格式的webservice调用
		return 0;
	}

	@Override
	public SGWChannel getSGWChannel() {
		return this.channel;
	}

	@Override
	public void stop() {
		logger.info("stop SoapChannel: " + this.channel.getChannelHost()+ " ...");
		if (server != null) {
			try {
				server.stop();
				logger.info("stop server: ");
			} catch (IOException e) {
				logger.warn("stop server IOException:", e);
			}
		}
		this.channel.setStatus(NodeStatus.OFF_LINE);
		confSrv.updateChannelStatus2DB(this.channel.getId(),NodeStatus.OFF_LINE);
		try {
			logger.info("wait 3s to exit...");
			Thread.sleep(3 * 1000);
		} catch (InterruptedException e) {
			logger.warn("Thread.sleep InterruptedException:", e);
		}
	}

	@Override
	public void addPersist(Node node) {

	}

	@Override
	public void deletePersist(Node node) {

	}

	public int getThreadPoolSize() {
		return executor.getPoolSize();
	}

	@Override
	public int getThreadPoolQueueSize() {
		return executor.getQueue().size();
	}

	@Override
	public int getNodeSendQueueSize(String nodeHostId) {
		return 0;
	}

	@Override
	public int getThreadPoolActiveCount() {
		return executor.getActiveCount();
	}

	public String getTranRecharge(String key, String url,
			Map<String, Object> map, XmlMessage reqXmlMessage,
			PrintStream body, long receiveTime) throws Exception {

		logger.info("key========" + key);
		logger.info("url========" + url);
		logger.info("wingRecharge========" + map.toString());
		logger.info("reqXmlMessage========" + reqXmlMessage.getDATA());

		StringBuffer params = new StringBuffer();
		params.append("{\"PARAMS\":{");
		if (map.get("BECHARGEDNO") != null
				&& !"".equals(map.get("BECHARGEDNO"))) {
			params.append("\"BECHARGEDNO\":");
			params.append("\"" + map.get("BECHARGEDNO").toString() + "\",");
		}

		params.append("\"ACCEPTORGCODE\":");
		params.append("\"" + map.get("ACCEPTORGCODE").toString() + "\",");
		logger.info("ACCEPTORGCODE========"
				+ map.get("ACCEPTORGCODE").toString());
		params.append("\"ACCEPTTIME\":");
		params.append("\"" + map.get("ACCEPTTIME").toString() + "\",");
		logger.info("ACCEPTTIME========" + map.get("ACCEPTTIME").toString());
		params.append("\"PAYTYPE\":");
		params.append("\"" + map.get("PAYTYPE").toString() + "\",");
		logger.info("PAYTYPE========" + map.get("PAYTYPE").toString());
		params.append("\"ACCOUNTID\":");
		params.append("\"" + map.get("ACCOUNTID").toString() + "\",");
		logger.info("ACCOUNTID========" + map.get("ACCOUNTID").toString());
		params.append("\"SUPPLYORGCODE\":");
		params.append("\"" + map.get("SUPPLYORGCODE").toString() + "\",");
		logger.info("SUPPLYORGCODE========"
				+ map.get("SUPPLYORGCODE").toString());
		if (map.get("BANKCARDNO") != null && !"".equals(map.get("BANKCARDNO"))) {
			params.append("\"BANKCARDNO\":");
			params.append("\"" + map.get("BANKCARDNO").toString() + "\",");
			logger.info("BANKCARDNO========" + map.get("BANKCARDNO").toString());
		}

		if (map.get("TXNTYPE") != null && !"".equals(map.get("TXNTYPE"))) {
			params.append("\"TXNTYPE\":");
			params.append("\"" + map.get("TXNTYPE").toString() + "\",");
			logger.info("TXNTYPE========" + map.get("TXNTYPE").toString());
		}
		
		/////////////////////////////////////////////
		if (map.get("RECHARGEAMT") != null && !"".equals(map.get("RECHARGEAMT"))) {
			params.append("\"RECHARGEAMT\":");
			params.append("\"" + map.get("RECHARGEAMT").toString() + "\",");
			logger.info("RECHARGEAMT========" + map.get("RECHARGEAMT").toString());
		}
		////////////////////////////////////////////

		params.append("\"TXNAMOUNT\":");
		params.append("\"" + map.get("TXNAMOUNT").toString() + "\",");
		logger.info("TXNAMOUNT========" + map.get("TXNAMOUNT").toString());

		if (map.get("BANKACCNAME") != null
				&& !"".equals(map.get("BANKACCNAME"))) {
			params.append("\"BANKACCNAME\":");
			params.append("\"" + map.get("BANKACCNAME").toString() + "\",");
			logger.info("BANKACCNAME========"
					+ map.get("BANKACCNAME").toString());
		}

		params.append("\"ACCEPTSEQNO\":");
		params.append("\"" + map.get("ACCEPTSEQNO").toString() + "\",");
		logger.info("ACCEPTSEQNO========" + map.get("ACCEPTSEQNO").toString());

		params.append("\"ACCEPTCHANNEL\":");
		params.append("\"" + map.get("ACCEPTCHANNEL").toString() + "\",");
		logger.info("ACCEPTCHANNEL========"
				+ map.get("ACCEPTCHANNEL").toString());

		if (map.get("TELBALANCE") != null && !"".equals(map.get("TELBALANCE"))) {
			params.append("\"TELBALANCE\":");
			params.append("\"" + map.get("TELBALANCE").toString() + "\",");
			logger.info("TELBALANCE========" + map.get("TELBALANCE").toString());
		}

		params.append("\"RECHARGETYPE\":");
		params.append("\"" + map.get("RECHARGETYPE").toString() + "\",");
		logger.info("RECHARGETYPE========" + map.get("RECHARGETYPE").toString());

		if (map.get("OPERATOR") != null && !"".equals(map.get("OPERATOR"))) {
			params.append("\"OPERATOR\":");
			params.append("\"" + map.get("OPERATOR").toString() + "\",");
			logger.info("OPERATOR========" + map.get("OPERATOR").toString());
		}

		if (map.get("OPERATEORG") != null && !"".equals(map.get("OPERATEORG"))) {
			params.append("\"OPERATEORG\":");
			params.append("\"" + map.get("OPERATEORG").toString() + "\",");
			logger.info("OPERATEORG========" + map.get("OPERATEORG").toString());
		}
		
		params.append("\"ACCOUNTIDTYPE\":");
		params.append("\"" + map.get("ACCOUNTIDTYPE").toString() + "\"}");
		logger.info("ACCOUNTIDTYPE========"
				+ map.get("ACCOUNTIDTYPE").toString());

		params.append(",\"APP_CODE\":\""
				+ tyConfigService.getValue("APP_CODE", "") + "\",\"IP\":\""
				+ tyConfigService.getValue("IP", "")
				+ "\",\"SERVICE_CODE\":\"P20020\",\"VERSION\":\""
				+ tyConfigService.getValue("VERSION", "") + "\"}");

		logger.info("APP_CODE========"
				+ tyConfigService.getValue("APP_CODE", ""));
		logger.info("IP========" + tyConfigService.getValue("IP", ""));
		logger.info("VERSION========" + tyConfigService.getValue("VERSION", ""));

		logger.info("======获取交易密钥=======发送给集团的字符串=" + params.toString());

		ThreeDESKeyParam des = ThreeDESKeyParam.getInstance();
		String strEnc = des.getEncString(params.toString(), key);

		String json = "{\"REQ_HEAD\":{\"ACCEPTORGCODE\":\""
				+ map.get("ACCEPTORGCODE").toString()
				+ "\"},\"REQ_BODY\":{\"ENCRYPTSTR\":\"" + strEnc + "\"}}";

		logger.info("======获取交易密钥=======发送给集团包含密文的字符串=" + json);

		String result = postHttpReqTimeout(url, json);
//		reqText = new String(reqText.getBytes("ISO8859-1"), "UTF-8");
		
		String responSecode = "";
		if(result!=null&&(!"".equals(result)||"0".equals(result))){
			Element serviceInformation=null;
			if("0".equals(result)){
				responSecode="000000";
				serviceInformation= DocumentHelper.createElement("Service_Information");
				Element element = serviceInformation.addElement("Result");
				element.setText("0");
				element = serviceInformation.addElement("CURRDATE");
				element.setText("");
				element = serviceInformation.addElement("BALANCE");
				element.setText("");
				element = serviceInformation.addElement("TXNAMT");
				element.setText("");
				element = serviceInformation.addElement("CHARGEDAMT");
				element.setText("");
				element = serviceInformation.addElement("YCCARDNO");
				element.setText("");
				element = serviceInformation.addElement("YCCARDPWD");
				element.setText("");
				element = serviceInformation.addElement("RESPONSECODE");
				element.setText("000000");
				element = serviceInformation.addElement("RESPONSECONTENT");
				element.setText("");
			}else{
				logger.info("===result=="+result );
				
				JSONObject jsonObject = JSONObject.fromObject(result);
				String repHead = jsonObject.getString("RSP_HEAD");
				logger.info("======获取交易密钥返回的消息RSP_HEAD=" + repHead);

				JSONObject jsonRepHead = JSONObject.fromObject(repHead);
				responSecode = jsonRepHead.getString("RESPONSECODE");
				logger.info("======获取交易密钥返回的消息RESPONSECODE=" + responSecode);

				String responSecontent = jsonRepHead.getString("RESPONSECONTENT");
				logger.info("======获取交易密钥返回的消息RESPONSECONTENT=" + responSecontent);


			    serviceInformation = DocumentHelper.createElement("Service_Information");

				Element element = serviceInformation.addElement("Result");
				if (responSecode.equals("000000")) {
					element.setText("0");
					String rspBody = jsonObject.getString("RSP_BODY");
					logger.info("=====获取交易密钥返回的消息，需要解密的RSP_BODY=" + rspBody);
					JSONObject jsonRspBody = JSONObject.fromObject(rspBody);
					String encryptStr = jsonRspBody.getString("ENCRYPTSTR");
					logger.info("=====获取交易密钥返回的消息，需要解密的串ENCRYPTSTR=" + encryptStr);

					String strDes = des.getDesString(encryptStr, key);
					logger.info("=====获取解密后的字符串=" + strDes);
					jsonObject = JSONObject.fromObject(strDes);
					String currdate = jsonObject.getString("CURRDATE");
					String balance = jsonObject.getString("BALANCE");
					String txnamt = jsonObject.getString("TXNAMT");
					String chargedamt = jsonObject.getString("CHARGEDAMT");
					String yccardno = jsonObject.getString("YCCARDNO");
					String yccardpwd = jsonObject.getString("YCCARDPWD");
					
					element = serviceInformation.addElement("CURRDATE");
					if (currdate == null || currdate.equals("")) {
						element.setText("");
					} else {
						element.setText(currdate);
					}
					element = serviceInformation.addElement("BALANCE");
					if (balance == null || balance.equals("")) {
						element.setText("");
					} else {
						element.setText(balance);
					}
					element = serviceInformation.addElement("TXNAMT");
					if (txnamt == null || txnamt.equals("")) {
						element.setText("");
					} else {
						element.setText(txnamt);
					}
					element = serviceInformation.addElement("CHARGEDAMT");
					if (chargedamt == null || chargedamt.equals("")) {
						element.setText("");
					} else {
						element.setText(chargedamt);
					}
					element = serviceInformation.addElement("YCCARDNO");
					if (yccardno == null || yccardno.equals("")) {
						element.setText("");
					} else {
						element.setText(yccardno);
					}
					element = serviceInformation.addElement("YCCARDPWD");
					if (yccardpwd == null || yccardpwd.equals("")) {
						element.setText("");
					} else {
						element.setText(yccardpwd);
					}
				} else {
					element.setText("-1");
					BusinessRecordPort bean= new BusinessRecordPort();
					bean.setSessionId(reqXmlMessage.getMID());
					bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
							.currentTimeMillis()));
					bean.setRequestHost(reqXmlMessage.getUID());
					bean.setServiceContextId(reqXmlMessage.getSCID());
					bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
							.currentTimeMillis()));
					bean.setResult(-1);
					TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
					tmallLogDao1.insertBusinessRecordPort(bean);	
				}
				element = serviceInformation.addElement("RESPONSECODE");
				if (responSecode == null || responSecode.equals("")) {
					element.setText("");
				} else {
					element.setText(responSecode);
				}
				element = serviceInformation.addElement("RESPONSECONTENT");
				if (responSecontent == null || responSecontent.equals("")) {
					element.setText("");
				} else {
					element.setText(responSecontent);
				}
			}
			
			XmlMessage ack = new XmlMessage(true);
			ack.setMID(reqXmlMessage.getMID());
			ack.setREPTAG(0);
			ack.setRTT(String.valueOf(receiveTime));
			ack.setSIG(null);
			ack.setRC("0");
			ack.setDS("SUCCESS");
			ack.setDATA(serviceInformation.asXML());
			String respXML = convertResponseString(ack);
			logger.info("=======================respXML========================");
			logger.info(respXML);
			logger.info("=======================respXML========================");
			byte[] resps = respXML.getBytes("UTF-8");
			ack.setLength(resps.length);
			ack.setMsgTime(System.currentTimeMillis());
			body.write(resps);
			body.close();
			
			return responSecode;
		}else{
			Element serviceInformationRecharge = DocumentHelper
					.createElement("Service_Information");
			Element elementRe = serviceInformationRecharge
					.addElement("Result");
			elementRe.setText("1");
			elementRe = serviceInformationRecharge.addElement("RESPONSECODE");
			elementRe.setText("17004");
			
			elementRe = serviceInformationRecharge.addElement("RESPONSECONTENT");
			elementRe.setText("");
			elementRe = serviceInformationRecharge.addElement("CURRDATE");
			elementRe.setText("");
			elementRe = serviceInformationRecharge.addElement("BESTPAYBALANCE");
			elementRe.setText("");
			elementRe = serviceInformationRecharge.addElement("TELBALANCE");
			elementRe.setText("");
			elementRe = serviceInformationRecharge.addElement("TOTALBALANCE");
			elementRe.setText("");
			elementRe = serviceInformationRecharge.addElement("ISBESTPAYACCT");
			elementRe.setText("");
			
			XmlMessage ack1 = new XmlMessage(true);
			ack1.setMID(reqXmlMessage.getMID());
			ack1.setREPTAG(0);
			ack1.setRTT(String.valueOf(receiveTime));
			ack1.setSIG(null);
			ack1.setRC("0");
			ack1.setDS("postHttpReqTimeout");
			ack1.setDATA(serviceInformationRecharge.asXML());
			String respXMLa = convertResponseString(ack1);
			logger.info(respXMLa);
			byte[] resps = respXMLa.getBytes("UTF-8");
			ack1.setLength(resps.length);
			ack1.setMsgTime(System.currentTimeMillis());
			body.write(resps);
			body.close();
			return responSecode;
		}
		
		
	}

	public void getQueryRecharge(String key, String url,
			Map<String, Object> map, XmlMessage reqXmlMessage,
			PrintStream body, long receiveTime) throws Exception {
		logger.info("key========" + key);
		logger.info("url========" + url);
		logger.info("wingRecharge========" + map.toString());
		logger.info("reqXmlMessage========" + reqXmlMessage.getDATA());
		StringBuffer params = new StringBuffer();
		params.append("{\"PARAMS\":{");
		params.append("\"ACCOUNTIDTYPE\":");
		params.append("\"" + map.get("ACCOUNTIDTYPE").toString() + "\",");
		params.append("\"ACCOUNTID\":");
		params.append("\"" + map.get("ACCOUNTID").toString() + "\",");

		if (map.get("TXNTYPE") != null && !"".equals(map.get("TXNTYPE"))) {
			params.append("\"TXNTYPE\":");
			params.append("\"" + map.get("TXNTYPE").toString() + "\",");
		}

		if (map.get("TXNAMOUNT") != null && !"".equals(map.get("TXNAMOUNT"))) {
			params.append("\"TXNAMOUNT\":");
			params.append("\"" + map.get("TXNAMOUNT").toString() + "\",");
		}

		params.append("\"SUPPLYORGCODE\":");
		params.append("\"" + map.get("SUPPLYORGCODE").toString() + "\",");

		params.append("\"ACCEPTORGCODE\":");
		params.append("\"" + map.get("ACCEPTORGCODE").toString() + "\",");

		if (map.get("ACCEPTCHANNEL") != null
				&& !"".equals(map.get("ACCEPTCHANNEL"))) {
			params.append("\"ACCEPTCHANNEL\":");
			params.append("\"" + map.get("ACCEPTCHANNEL").toString() + "\",");
		}

		params.append("\"ACCEPTSEQNO\":");
		params.append("\"" + map.get("ACCEPTSEQNO").toString() + "\",");

		if (map.get("ACCEPTTIME") != null && !"".equals(map.get("ACCEPTTIME"))) {
			params.append("\"ACCEPTTIME\":");
			params.append("\"" + map.get("ACCEPTTIME").toString() + "\",");
		}

		if (map.get("OLDACCETTIME") != null
				&& !"".equals(map.get("OLDACCETTIME"))) {
			params.append("\"OLDACCETTIME\":");
			params.append("\"" + map.get("OLDACCETTIME").toString() + "\",");
		}
		
		params.append("\"OLDACCEPTSEQNO\":");
		params.append("\"" + map.get("OLDACCEPTSEQNO").toString() + "\"}");

		params.append(",\"APP_CODE\":\""
				+ tyConfigService.getValue("APP_CODE", "") + "\",\"IP\":\""
				+ tyConfigService.getValue("IP", "")
				+ "\",\"SERVICE_CODE\":\"P30033\",\"VERSION\":\""
				+ tyConfigService.getValue("VERSION", "") + "\"}");

		logger.info("======获取交易密钥=======发送给集团的字符串=" + params.toString());

		ThreeDESKeyParam des = ThreeDESKeyParam.getInstance();
		String strEnc = des.getEncString(params.toString(), key);

		String json = "{\"REQ_HEAD\":{\"ACCEPTORGCODE\":\""
				+ map.get("ACCEPTORGCODE").toString()
				+ "\"},\"REQ_BODY\":{\"ENCRYPTSTR\":\"" + strEnc + "\"}}";
		logger.info("======获取交易密钥=======发送给集团包含密文的字符串=" + json);

		String reqText = postHttpReq(json, url);
//		reqText = new String(reqText.getBytes("ISO8859-1"), "UTF-8");
		logger.info("======获取交易密钥=======集团返回的包含密文的字符串=" + reqText);

		JSONObject jsonObject = JSONObject.fromObject(reqText);
		String repHead = jsonObject.getString("RSP_HEAD");
		logger.info("======获取交易密钥返回的消息RSP_HEAD=" + repHead);

		JSONObject jsonRepHead = JSONObject.fromObject(repHead);
		String responSecode = jsonRepHead.getString("RESPONSECODE");
		logger.info("======获取交易密钥返回的消息RESPONSECODE=" + responSecode);

		String responSecontent = jsonRepHead.getString("RESPONSECONTENT");
		logger.info("======获取交易密钥返回的消息RESPONSECONTENT=" + responSecontent);

		Element serviceInformation = DocumentHelper.createElement("Service_Information");
		Element element = serviceInformation.addElement("Result");
		if (responSecode.equals("000000")) {
			element.setText("0");
			
			String rspBody = jsonObject.getString("RSP_BODY");
			logger.info("=====获取交易密钥返回的消息，需要解密的RSP_BODY=" + rspBody);
			JSONObject jsonRspBody = JSONObject.fromObject(rspBody);
			String encryptStr = jsonRspBody.getString("ENCRYPTSTR");
			logger.info("=====获取交易密钥返回的消息，需要解密的串ENCRYPTSTR=" + encryptStr);

			String strDes = des.getDesString(encryptStr, key);
			logger.info("=====获取解密后的字符串=" + strDes);
			
			jsonObject = JSONObject.fromObject(strDes);
			String chargeresult = jsonObject.getString("CHARGERESULT");
			String currdate = jsonObject.getString("CURRDATE");
			String balance = jsonObject.getString("BALANCE");
			String txnamt = jsonObject.getString("TXNAMT");
			String chargedamt = jsonObject.getString("CHARGEDAMT");
			String yccardno = jsonObject.getString("YCCARDNO");
			String yccardpwd = jsonObject.getString("YCCARDPWD");
			String chargeresultdesc = jsonObject.getString("CHARGERESULTDESC");
			String telrechargestatus = jsonObject.getString("TELRECHARGESTATUS");
			String telrechargestatusdesc = jsonObject.optString("TELRECHARGESTATUSDESC");
			
			element = serviceInformation.addElement("CHARGERESULTDESC");
			if (chargeresultdesc == null || chargeresultdesc.equals("")) {
				element.setText("");
			} else {
				element.setText(chargeresultdesc);
			}element = serviceInformation.addElement("TELRECHARGESTATUS");
			if (telrechargestatus == null || telrechargestatus.equals("")) {
				element.setText("");
			} else {
				element.setText(telrechargestatus);
			}element = serviceInformation.addElement("TELRECHARGESTATUSDESC");
			if (telrechargestatusdesc == null || telrechargestatusdesc.equals("")) {
				element.setText("");
			} else {
				element.setText(telrechargestatusdesc);
			}
			element = serviceInformation.addElement("CHARGERESULT");
			if (chargeresult == null || chargeresult.equals("")) {
				element.setText("");
			} else {
				element.setText(chargeresult);
			}
			element = serviceInformation.addElement("CURRDATE");
			if (currdate == null || currdate.equals("")) {
				element.setText("");
			} else {
				element.setText(currdate);
			}
			element = serviceInformation.addElement("BALANCE");
			if (balance == null || balance.equals("")) {
				element.setText("");
			} else {
				element.setText(balance);
			}
			element = serviceInformation.addElement("TXNAMT");
			if (txnamt == null || txnamt.equals("")) {
				element.setText("");
			} else {
				element.setText(txnamt);
			}
			element = serviceInformation.addElement("CHARGEDAMT");
			
			logger.info("====CHARGEDAMT====" + chargedamt);
			if (chargedamt == null || chargedamt.equals("")) {
				element.setText("");
			} else {
				element.setText(chargedamt);
			}
			element = serviceInformation.addElement("YCCARDNO");
			if (yccardno == null || yccardno.equals("")) {
				element.setText("");
			} else {
				element.setText(yccardno);
			}
			element = serviceInformation.addElement("YCCARDPWD");
			if (yccardpwd == null || yccardpwd.equals("")) {
				element.setText("");
			} else {
				element.setText(yccardpwd);
			}
		} else {
			element.setText("-1");
			BusinessRecordPort bean= new BusinessRecordPort();
			bean.setSessionId(reqXmlMessage.getMID());
			bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
					.currentTimeMillis()));
			bean.setRequestHost(reqXmlMessage.getUID());
			bean.setServiceContextId(reqXmlMessage.getSCID());
			bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
					.currentTimeMillis()));
			bean.setResult(-1);
			TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
			tmallLogDao1.insertBusinessRecordPort(bean);	
		}

		element = serviceInformation.addElement("RESPONSECODE");
		if (responSecode == null || responSecode.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecode);
		}
		element = serviceInformation.addElement("RESPONSECONTENT");
		if (responSecontent == null || responSecontent.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecontent);
		}

		XmlMessage ack = new XmlMessage(true);
		ack.setMID(reqXmlMessage.getMID());
		ack.setREPTAG(0);
		ack.setRTT(String.valueOf(receiveTime));
		ack.setSIG(null);
		ack.setRC("0");
		ack.setDS("SUCCESS");
		ack.setDATA(serviceInformation.asXML());
		String respXML = convertResponseString(ack);
		logger.info("=======================respXML========================");
		logger.info(respXML);
		logger.info("=======================respXML========================");
		byte[] resps = respXML.getBytes("UTF-8");
		ack.setLength(resps.length);
		ack.setMsgTime(System.currentTimeMillis());
		body.write(resps);
		body.close();
	}

	public static String postHttpReq(String json, String url) {
		logger.info("postHttpReq");
		logger.info("url"+url);
		EntityEnclosingMethod postMethod =null;
		String responseMsg = "";
		int statusCode = 0;
		try {
			HttpClient httpClient = new HttpClient();

			byte b[] = json.getBytes();// 把字符串转换为二进制数据
			RequestEntity requestEntity = new ByteArrayRequestEntity(b);

			postMethod = new PostMethod();
			postMethod.setRequestEntity(requestEntity);// 设置数据
			postMethod.setPath(url);// 设置服务的url
			// postMethod.setRequestHeader("Content-Type",
			// "application/soap+xml; charset=UTF-8");// 设置请求头编码
			httpClient.getParams().setContentCharset("UTF-8");
			// 设置连接超时
			httpClient.getHttpConnectionManager().getParams()
					.setConnectionTimeout(5 * 1000);
			// 设置读取超时
			httpClient.getHttpConnectionManager().getParams()
					.setSoTimeout(20 * 1000);
			httpClient.getHttpConnectionManager().getParams()
					.setSoTimeout(60 * 1000);
			statusCode = httpClient.executeMethod(postMethod);// 发送请求
			logger.info("HTTP statusCode" + statusCode);
			responseMsg = postMethod.getResponseBodyAsString();// 获取返回值
		} catch (Exception e) {
			logger.info("postHttpReq服务异常" + e);
		} finally {
			postMethod.releaseConnection();// 释放连接
		}
		
		return responseMsg;
	}
	
	
	public static String postHttpReqTimeout(String urlStr, String xmlInfo) {
		logger.info("postHttpReqTimeout request start");
		logger.info("urlStr:"+urlStr);
		logger.info("xmlInfo:"+xmlInfo);
		String result = "";
		HttpURLConnection con =null;
		try {
			URL url = new URL(urlStr);
			con = (HttpURLConnection)url.openConnection();
			con.setConnectTimeout(5000);
			con.setReadTimeout(20000);
			con.setDoOutput(true);
			con.setRequestProperty("Pragma", "no-cache");
			con.setRequestProperty("Cache-Control", "no-cache");
			con.setRequestProperty("Content-Type", "text/xml");
			con.connect();
			
			OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
			out.write(new String(xmlInfo.getBytes("UTF-8")));
			out.flush();
			out.close();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream(),"UTF-8"));
			String line = "";
			
			logger.info("HTTP statusCode" + con.getResponseCode());
			if(con.getResponseCode()==HttpStatus.SC_REQUEST_TIMEOUT){
				return "0";
			}
			StringBuffer sb = new StringBuffer();
			for (line = br.readLine(); line != null; line = br.readLine()) {
				sb.append(line);
			}
			result = sb.toString();
		} catch (SocketTimeoutException e) {
            logger.info("Read timed out：" , e);
			if(e.toString().contains("Read timed out")){
				return "0";
			}else{
				return null;
			}
		}catch (Exception e) {
			logger.info("HTTP服务异常：" , e);
			return null;
		}
		return result;
	}
	
	public void getBalanceQuery(String key, String acceptOrgCode, String url,
			WingBalanceQuery wingBalanceQuery, XmlMessage reqXmlMessage,
			PrintStream body, long receiveTime) throws Exception {
		
		logger.info("key========" + key);
		logger.info("acceptOrgCode========" + acceptOrgCode);
		logger.info("url========" + url);
		logger.info("reqXmlMessage========" + reqXmlMessage.getDATA());
		StringBuffer params = new StringBuffer();
		params.append("{\"PARAMS\":{");
		params.append("\"ACCOUNTIDTYPE\":");
		params.append("\"" + wingBalanceQuery.getAccountidtype() + "\",");
		params.append("\"QUERYTYPE\":");
		params.append("\"" + wingBalanceQuery.getQuerytype() + "\",");
		if (wingBalanceQuery.getAcceptchannel() != null
				&& !"".equals(wingBalanceQuery.getAcceptchannel())) {
			params.append("\"ACCEPTCHANNEL\":");
			params.append("\"" + wingBalanceQuery.getAcceptchannel() + "\",");
		}
		params.append("\"ACCEPTSEQNO\":");
		params.append("\"" + wingBalanceQuery.getAcceptseqno() + "\",");

		if (wingBalanceQuery.getAccepttime() != null
				&& !"".equals(wingBalanceQuery.getAccepttime())) {
			params.append("\"ACCEPTTIME\":");
			params.append("\"" + wingBalanceQuery.getAccepttime() + "\",");
		}
		
		params.append("\"ACCOUNTID\":");
		params.append("\"" + wingBalanceQuery.getAccountid() + "\"}");
		
		params.append(",\"APP_CODE\":\""
				+ tyConfigService.getValue("APP_CODE", "") + "\",\"IP\":\""
				+ tyConfigService.getValue("IP", "")
				+ "\",\"SERVICE_CODE\":\"P30160\",\"VERSION\":\""
				+ tyConfigService.getValue("VERSION", "") + "\"}");

		logger.info("======获取交易密钥=======发送给集团的字符串=" + params.toString());

		ThreeDESKeyParam des = ThreeDESKeyParam.getInstance();
		String strEnc = des.getEncString(params.toString(), key);

		String json = "{\"REQ_HEAD\":{\"ACCEPTORGCODE\":\""+wingBalanceQuery.getAcceptorgcode()+"\"},\"REQ_BODY\":{\"ENCRYPTSTR\":\""
				+ strEnc + "\"}}";

		logger.info("======获取交易密钥=======发送给集团包含密文的字符串=" + json);

		String reqText = postHttpReq(json, url);
//		reqText = new String(reqText.getBytes("ISO8859-1"), "UTF-8");	
		logger.info("======获取交易密钥=======集团返回的包含密文的字符串=" + reqText);

		JSONObject jsonObject = JSONObject.fromObject(reqText);
		String repHead = jsonObject.getString("RSP_HEAD");
		logger.info("======获取交易密钥返回的消息RSP_HEAD=" + repHead);

		JSONObject jsonRepHead = JSONObject.fromObject(repHead);
		String responSecode = jsonRepHead.getString("RESPONSECODE");
		logger.info("======获取交易密钥返回的消息RESPONSECODE=" + responSecode);

		String responSecontent = jsonRepHead.getString("RESPONSECONTENT");
		logger.info("======获取交易密钥返回的消息RESPONSECONTENT=" + responSecontent);
		

		Element serviceInformation = DocumentHelper.createElement("Service_Information");
		
		Element element = serviceInformation.addElement("Result");
		if (responSecode.equals("000000")) {
			element.setText("0");
			
			String rspBody = jsonObject.getString("RSP_BODY");
			logger.info("=====获取交易密钥返回的消息，需要解密的RSP_BODY=" + rspBody);
			JSONObject jsonRspBody = JSONObject.fromObject(rspBody);
			String encryptStr = jsonRspBody.getString("ENCRYPTSTR");
			logger.info("=====获取交易密钥返回的消息，需要解密的串ENCRYPTSTR=" + encryptStr);

			String strDes = des.getDesString(encryptStr, key);
			logger.info("=====获取解密后的字符串=" + strDes);
			jsonObject = JSONObject.fromObject(strDes);

			String currdate = jsonObject.getString("CURRDATE");
			String bestpaybalance = jsonObject.getString("BESTPAYBALANCE");
			String telbalance = jsonObject.getString("TELBALANCE");
			String totalbalance = jsonObject.getString("TOTALBALANCE");
			String isbestpayacct = jsonObject.getString("ISBESTPAYACCT");
			
			
			element = serviceInformation.addElement("CURRDATE");
			if (currdate == null || currdate.equals("")) {
				element.setText("");
			} else {
				element.setText(currdate);
			}
			element = serviceInformation.addElement("BESTPAYBALANCE");
			if (bestpaybalance == null || bestpaybalance.equals("")) {
				element.setText("");
			} else {
				element.setText(bestpaybalance);
			}
			element = serviceInformation.addElement("TELBALANCE");
			if (telbalance == null || telbalance.equals("")) {
				element.setText("");
			} else {
				element.setText(telbalance);
			}
			element = serviceInformation.addElement("TOTALBALANCE");
			if (totalbalance == null || totalbalance.equals("")) {
				element.setText("");
			} else {
				element.setText(totalbalance);
			}
			element = serviceInformation.addElement("ISBESTPAYACCT");
			if (isbestpayacct == null || isbestpayacct.equals("")) {
				element.setText("");
			} else {
				element.setText(isbestpayacct);
			}
			
		} else {
			element.setText("-1");
			BusinessRecordPort bean= new BusinessRecordPort();
			bean.setSessionId(reqXmlMessage.getMID());
			bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
					.currentTimeMillis()));
			bean.setRequestHost(reqXmlMessage.getUID());
			bean.setServiceContextId(reqXmlMessage.getSCID());
			bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
					.currentTimeMillis()));
			bean.setResult(-1);
			TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
			
			tmallLogDao1.insertBusinessRecordPort(bean);
		}
		
		element = serviceInformation.addElement("RESPONSECODE");
		if (responSecode == null || responSecode.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecode);
		}
		element = serviceInformation.addElement("RESPONSECONTENT");
		if (responSecontent == null || responSecontent.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecontent);
		}

		XmlMessage ack = new XmlMessage(true);
		ack.setMID(reqXmlMessage.getMID());
		ack.setREPTAG(0);
		ack.setRTT(String.valueOf(receiveTime));
		ack.setSIG(null);
		ack.setRC("0");
		ack.setDS("SUCCESS");
		ack.setDATA(serviceInformation.asXML());
		String respXML = convertResponseString(ack);
		logger.info("=======================respXML========================");
		logger.info(respXML);
		logger.info("=======================respXML========================");
		byte[] resps = respXML.getBytes("UTF-8");
		ack.setLength(resps.length);
		ack.setMsgTime(System.currentTimeMillis());
		body.write(resps);
		body.close();
	}
	
	private String getRechargeRollback(String key,String url,Map<String, Object> map, XmlMessage reqXmlMessage,PrintStream body, long receiveTime) throws Exception {
		logger.info("key========" + key);
		logger.info("url========" + url);
		logger.info("wingRecharge========" + map.toString());
		logger.info("reqXmlMessage========" + reqXmlMessage.getDATA());
		
		StringBuffer params = new StringBuffer();
		params.append("{\"PARAMS\":{");
		params.append("\"ACCOUNTIDTYPE\":");
		params.append("\"" + map.get("ACCOUNTIDTYPE").toString() + "\",");
		params.append("\"ACCOUNTID\":");
		params.append("\"" + map.get("ACCOUNTID").toString() + "\",");
		if (map.get("TXNTYPE") != null && !"".equals(map.get("TXNTYPE"))) {
			params.append("\"TXNTYPE\":");
			params.append("\"" + map.get("TXNTYPE").toString() + "\",");
		}

		if (map.get("TXNAMOUNT") != null && !"".equals(map.get("TXNAMOUNT"))) {
			params.append("\"TXNAMOUNT\":");
			params.append("\"" + map.get("TXNAMOUNT").toString() + "\",");
		}

		params.append("\"SUPPLYORGCODE\":");
		params.append("\"" + map.get("SUPPLYORGCODE").toString() + "\",");

		params.append("\"ACCEPTORGCODE\":");
		params.append("\"" + map.get("ACCEPTORGCODE").toString() + "\",");

		if (map.get("ACCEPTCHANNEL") != null&& !"".equals(map.get("ACCEPTCHANNEL"))) {
			params.append("\"ACCEPTCHANNEL\":");
			params.append("\"" + map.get("ACCEPTCHANNEL").toString() + "\",");
		}

		

		if (map.get("ACCEPTTIME") != null && !"".equals(map.get("ACCEPTTIME"))) {
			params.append("\"ACCEPTTIME\":");
			params.append("\"" + map.get("ACCEPTTIME").toString() + "\",");
		}

		params.append("\"OLDACCEPTSEQNO\":");
		params.append("\"" + map.get("OLDACCEPTSEQNO").toString() + "\",");
		
		
		if (map.get("OLDACCETTIME") != null&& !"".equals(map.get("OLDACCETTIME"))) {
			params.append("\"OLDACCETTIME\":");
			params.append("\"" + map.get("OLDACCETTIME").toString() + "\",");
		}
		
		params.append("\"ACCEPTSEQNO\":");
		params.append("\"" + map.get("ACCEPTSEQNO").toString() + "\"}");

		params.append(",\"APP_CODE\":\""
				+ tyConfigService.getValue("APP_CODE", "") + "\",\"IP\":\""
				+ tyConfigService.getValue("IP", "")
				+ "\",\"SERVICE_CODE\":\"P20031\",\"VERSION\":\""
				+ tyConfigService.getValue("VERSION", "") + "\"}");

		logger.info("======获取交易密钥=======发送给集团的字符串=" + params.toString());

		ThreeDESKeyParam des = ThreeDESKeyParam.getInstance();
		String strEnc = des.getEncString(params.toString(), key);

		String json = "{\"REQ_HEAD\":{\"ACCEPTORGCODE\":\""
				+ map.get("ACCEPTORGCODE").toString()
				+ "\"},\"REQ_BODY\":{\"ENCRYPTSTR\":\"" + strEnc + "\"}}";
		logger.info("======获取交易密钥=======发送给集团包含密文的字符串=" + json);

		String reqText = postHttpReq(json, url);
//		reqText = new String(reqText.getBytes("ISO8859-1"), "UTF-8");
		logger.info("======获取交易密钥=======集团返回的包含密文的字符串=" + reqText);

		JSONObject jsonObject = JSONObject.fromObject(reqText);
		String repHead = jsonObject.getString("RSP_HEAD");
		logger.info("======获取交易密钥返回的消息RSP_HEAD=" + repHead);

		JSONObject jsonRepHead = JSONObject.fromObject(repHead);
		String responSecode = jsonRepHead.getString("RESPONSECODE");
		logger.info("======获取交易密钥返回的消息RESPONSECODE=" + responSecode);

		String responSecontent = jsonRepHead.getString("RESPONSECONTENT");
		logger.info("======获取交易密钥返回的消息RESPONSECONTENT=" + responSecontent);

		

		Element serviceInformation = DocumentHelper.createElement("Service_Information");
		Element element = serviceInformation.addElement("Result");
		if (responSecode.equals("000000")) {
			element.setText("0");
			
			String rspBody = jsonObject.getString("RSP_BODY");
			logger.info("=====获取交易密钥返回的消息，需要解密的RSP_BODY=" + rspBody);
			JSONObject jsonRspBody = JSONObject.fromObject(rspBody);
			String encryptStr = jsonRspBody.getString("ENCRYPTSTR");
			logger.info("=====获取交易密钥返回的消息，需要解密的串ENCRYPTSTR=" + encryptStr);

			String strDes = des.getDesString(encryptStr, key);
			logger.info("=====获取解密后的字符串=" + strDes);
			jsonObject = JSONObject.fromObject(strDes);
			
			String currdate = jsonObject.getString("CURRDATE");
			String balance = jsonObject.getString("BALANCE");
			String thirdorderno = jsonObject.getString("THIRDORDERNO");
			
			element = serviceInformation.addElement("THIRDORDERNO");
			if (thirdorderno == null || thirdorderno.equals("")) {
				element.setText("");
			} else {
				element.setText(thirdorderno);
			}
			element = serviceInformation.addElement("CURRDATE");
			if (currdate == null || currdate.equals("")) {
				element.setText("");
			} else {
				element.setText(currdate);
			}
			element = serviceInformation.addElement("BALANCE");
			if (balance == null || balance.equals("")) {
				element.setText("");
			} else {
				element.setText(balance);
			}
		} else {
			element.setText("-1");
			BusinessRecordPort bean= new BusinessRecordPort();
			bean.setSessionId(reqXmlMessage.getMID());
			bean.setBusinessCallId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(System
					.currentTimeMillis()));
			bean.setRequestHost(reqXmlMessage.getUID());
			bean.setServiceContextId(reqXmlMessage.getSCID());
			bean.setResponseTime(new SimpleDateFormat("yyyyMMddHHmmss").format(System
					.currentTimeMillis()));
			bean.setResult(-1);
			TmallLogDao tmallLogDao1=(TmallLogDao)SpringContext.getInstance().getApplicationContext().getBean("tmallLogDao");	
			
			tmallLogDao1.insertBusinessRecordPort(bean);
		}

		element = serviceInformation.addElement("RESPONSECODE");
		if (responSecode == null || responSecode.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecode);
		}
		element = serviceInformation.addElement("RESPONSECONTENT");
		if (responSecontent == null || responSecontent.equals("")) {
			element.setText("");
		} else {
			element.setText(responSecontent);
		}

		XmlMessage ack = new XmlMessage(true);
		ack.setMID(reqXmlMessage.getMID());
		ack.setREPTAG(0);
		ack.setRTT(String.valueOf(receiveTime));
		ack.setSIG(null);
		ack.setRC("0");
		ack.setDS("SUCCESS");
		ack.setDATA(serviceInformation.asXML());
		String respXML = convertResponseString(ack);
		logger.info("=======================respXML========================");
		logger.info(respXML);
		logger.info("=======================respXML========================");
		byte[] resps = respXML.getBytes("UTF-8");
		ack.setLength(resps.length);
		ack.setMsgTime(System.currentTimeMillis());
		body.write(resps);
		body.close();
		return responSecode;
	}
	
	
	/**
	 * 由于计费侧提供的接口协议没变，只是地址调整，割接到3.0的本地网需要调用新的地址
	 * 获取判断使用的地址
	 * jf3_flag 刷新开关  配置为1则表示启用割接地市判断，配置为0则表示按现有的流程
	 * Jf3_jt_latn_id  割接地市配置项（多个地市用逗号分隔，如果配置项调整为888，则表示全部调用新地址）
	 * area_code 区域编码
	 * checkCode = ""; 需要对比的武汉编码 027 或者 1001
	 * result 1 新武汉 2 新湖北 3 旧武汉 4 旧湖北
	 */
	private int getURLForJf3(String area_code,String checkCode) {
		String str;
		jf3_flag = userResourceConfigService.getValue("jf3_flag","");
		jf3_area_code = userResourceConfigService.getValue("jf3_area_code","");
		jf3_latn_id = userResourceConfigService.getValue("jf3_latn_id","");
		if(checkCode.equals(IS_WH)){
			str = jf3_area_code;
		}else {
			str = jf3_latn_id;
		}
		logger.info("====== jf3_flag = "+jf3_flag);
		logger.info("====== str = "+str);
		logger.info("====== area_code = "+area_code);
		logger.info("====== checkCode = "+checkCode);
		if("1".equals(jf3_flag)) {
			if("888".equals(str)) {
				if(area_code.equals(checkCode)) {
					return 1;//新武汉
				}else {
					return 2;//新湖北
				}
			}else {
				String[] split_jt_latn_id = str.split(",");
				for (String string : split_jt_latn_id) {
					if(string.equals(area_code)) {
						//包含
						if(area_code.equals(checkCode)) {
							return 1;//新武汉
						}else {
							return 2;//新湖北
						}
					}
				}
			}
			
		}
		if(area_code.equals(checkCode)) {
			return 3;//旧武汉
		}else {
			return 4;//旧湖北
		}
	}
	
	
	public static void main(String[] args) {
	}
	
}